正在处理下面的代码。我想将两个元素的值作为数组返回。
public static int[]box ={20,50,60};
public static int[] getBoxDimensions(int[]box){
int[] dimension;
int length = box[0];
int width = box[box.length - 1];
{
dimension=[][];
}
return dimension;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println(getBoxDimensions(box));
}
最佳答案
然后你可以为 2 个 int 值创建一个数组,如下所示:
int[] dimension = new int[2];//create an array of size 3
dimension[0] = box[0];//add in the first position length
dimension[1] = box[box.length - 1];//add in the second position width
return dimension;//return your array
关于java - 返回盒子的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43951935/