title: Displaying Position of Array Elements in Java
body: <p>I'm trying to display the position(index) numbers of largest values in an array. It's an array with 100 random numbers. For some reason the output is correct after the first a few numbers. I always get wrong numbers in the beginning of the output. This is the code I have;
  Thanks</p>
  
  <pre><code>public static void main(String[] args) {
      int max = 0;
      int array[] = new int[100];
      System.out.println();
  
      // code to display student responses
      randomNum(array);
  
      System.out.println(" Survey Responses - 100 Students: ");
      response(array);
  
      System.out.println("Positions of the highest numbers");
      System.out.println();
  
      for (int i = 0; i &lt; array.length; i++) {
          max = Math.max(max, array[i]);
          if (array[i] == max) {
              System.out.println(i);
          }
      }
  }
  
  private static void randomNum(int A[]) {
      for (int i = 0; i &lt; A.length; i++) {
          A[i] = (int) (Math.random() * 10000) % 10 + 1;
      }
  
  }
  
  public static void response(int[] resp) {
      for (int x = 0; x &lt; resp.length; x++) {
          System.out.print(resp[x] + " ");
      }
      System.out.println();
  }
  </code></pre>