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

    return -1; 
} 

それは私がそれを配列に私に格納されているもの添加した以外は何をしたいのかを正確に行います。私もnumArray [i]を試しましたが、どちらもうまくいきません。なぜ私のコードは配列を印刷しませんか?

+0

'javascript!== java' –

+0

これは本当に間違っています、あなたはあなたがここに書いていると思いますか? –

+0

javascriptのは、静的なキーワードを持っていない、.... –

答えて

-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; 
} 
+0

を@OusmaneMahyDiaw感謝します彼はこれを使うことができます - > import static java.lang.System.out; 。それはあなたが間違っていないと言った。 –

関連する問題