Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found the same fix as everyone else. However, I also noticed that you were printing out 2 arrays that only included the number 0. You weren't using the random numbers at all to update the even or odd arrays. Also, the two display methods are identical. You don't need a separate method for each since you can use the display method to print out both arrays. This also applies to variables as well. You can reuse the same variable as long as you are no longer using it (Like the <code>index</code> variable in the code I wrote). I updated the code to simplify it, as well as fix all of the errors you had as follows:</p> <pre><code>public class PrintOddAndEvenArrays { public static void main(String[] args) { int[] randomNum = new int[500]; for (int x = 0; x &lt; randomNum.length; x++) { randomNum[x] = (int) (Math.random() * 25); } int index = 0; int[] oddArray = new int[100]; for (int x = 0; x &lt; randomNum.length; x++) { if(index == 100){ break; } if (randomNum[x] % 2 != 0){ oddArray[index] = randomNum[x]; index++; } } index = 0; int[] evenArray = new int[100]; for (int x = 0; x &lt; randomNum.length; x++) { if(index == 100){ break; } if (randomNum[x] % 2 == 0){ evenArray[index] = randomNum[x]; index++; } } display(oddArray); display(evenArray); } public static void display(int[] Array) { for(int a = 0; a &lt; Array.length-1;a++){ System.out.print(Array[a]+ ", "); if(a == Array.length-2){ System.out.print(Array[a+1]); } } System.out.print("\n"); } } </code></pre> <p>For future reference, to debug by yourself, the error printed out in the console usually tells you what line to reference to fix the error. Start by learning what the error is and how to fix it. Usually a quick Google search allows you to understand the error and how you can fix it. Then, once you can run the program, check your output with the desired output and make changes accordingly. With more complex errors, you'll have to debug by yourself, since the code will be a lot longer and more difficult for someone else to understand. Good luck!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload