-4
public static int getNextLargest(int[] numArray, int searchNum)
    {for(int i:numArray){
       out.println(i);
       if(searchNum < i){
           numArray.add(i);
       }
   }

    return -1;
}

It does exactly what I want it to do except for adding what is stored in i to an array. I have also tried numArray[i], it won't work either.

Graham
  • 1
  • 2

1 Answers1

-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;
}
  • he doesn't have to use "System.out.println(i);" he could use this --> import static java.lang.System.out; . That said, you're not wrong. – Ousmane D. Mar 13 '17 at 23:54