【发布时间】:2018-09-19 06:16:05
【问题描述】:
我有这样的功能
Class Return_two{
public static void main(String args[]){
int b=0;// Declare a variable
int a []= new int[3];// Declare an array [both are return at the end of the user define function fun()]
Return_two r=new Return_two();
int result_store= r.fun(a,b);//where should I store the result meaning is it a normal variable or an array where I store the result?
}
public int [] fun (int[] array,int var)//may be this is not a good Return type to returning an array with a variable so what will be change in return type?
{
for(int counter=0;counter <array.length;counter++)
{ var=var+counter;
}
return( array,var);// Here how could I return this two value in main function?
}
}
现在,这是我的问题。如上所述,我想返回一个带有变量的数组。但据我所知,可以返回一个数组或一个变量,但不能同时返回两者。或者可以返回一个或多个变量,使这些变量作为数组元素。但是如何在 main 函数中返回一个带有变量的数组呢?
【问题讨论】:
-
创建一个包裹两者的对象
-
你能解释清楚一点吗?
-
b 不是数组!
-
或者尝试使用 Pair,geeksforgeeks.org/pair-class-in-java
标签: java arrays return return-value return-type