public static int getNextLargest(int[] numArray, int searchNum)
{for(int i:numArray){
out.println(i);
if(searchNum < i){
numArray.add(i);
}
}
return -1;
}
除了将存储在i中的内容添加到数组中之外,它完全符合我的要求。我也尝试了numArray [i],它也无法工作。
答案 0 :(得分:-1)
public static int getNextLargest(int[] numArray, int searchNum)
{
for(int i:numArray){
//You should use System.out.println.
System.out.println(i);
//You are modifying the inputArray in this line
if(searchNum < i){
//1. There is no add method on integer, you can use ArrayList of Integers to use add method. ArrayList<Integer> numArray=new ArrayList<Integer>;
//2. int[] array will not increase its size automatically. You have use use ArrayList to do this
numArray.add(i);
}
}
return -1;
}