title: Java program involving arrays displays random numbers when it runs
body: <p>For my Java class, I have this assignment:</p>
  
  <blockquote>
    <p>Write a program that generates 100 random integers in the range 0 to 25, and stores them in an array. Then, the program should call a class method that sorts the odd numbers into an array and returns the array. The program should then call another method that sorts the even numbers into a separate array and returns the array. Both arrays should then be displayed.</p>
  </blockquote>
  
  <p>This is my code:</p>
  
  <pre><code>public class XandY
  {
      public static void main(String [] args)
      {
          int [] randomNums = new int [100];
          for (int i = 0; i &lt; randomNums.length; i++) { 
              randomNums[i] = (int) (Math.random() * 26); 
              int[] oddNums = sortOdd(randomNums);
              System.out.println("The odd numbers are "); 
              for (int n = 0; n&lt;=oddNums.length; n++) { 
              System.out.print(n); 
              } 
              int[] evenNums = sortEven(randomNums);
              System.out.println("The even numbers are ");
              for (int o = 0; o&lt;=evenNums.length; o++) { 
              System.out.print(o); 
              } 
          }
      }
  
      public static int[] sortOdd(int[] randomNums)
      {
          int numOdds = 0;
          for (int x : randomNums){
              if(x % 2 == 1){
              ++numOdds;
              }
          }
          int[] oddNums = new int[numOdds]; 
          int z = 0;
          for (int n : randomNums){
              if(n % 2 == 1){
                  oddNums[z] = n;
                  z++;
              }
          }
          return oddNums;
  
  
      } 
      public static int[] sortEven(int[] randomNums)
      {
          int numEvens = 0;
          for (int x : randomNums){
              if(x % 2 == 0){
              ++numEvens;
              }
          }
          int[] evenNums = new int[numEvens];
          int z = 0;
          for (int n : randomNums){
              if(n % 2 == 0){
                  evenNums[z] = n;
                  z++;
              }
          }
          return evenNums;
  
      }
  
  
  
  }
  </code></pre>
  
  <p>When it runs, it displays a bunch of random numbers. Could anyone help with this? Thanks in advance.</p>