0

I am trying to create a program that takes a array of 7 random numbers from 1-10 and puts them in a array and prints it,but whenever I run it I get this same result [I@6d06d69c.

import java.util.Random;

public class DiversCalc {
    public static void main(String[] args){


    int[] myList = new int[7];

    Random rand = new Random();

    for (int positionInArray = 0; positionInArray < myList.length; 
    positionInArray++) {
        int diverScore1 = rand.nextInt(10);
        myList[positionInArray] = diverScore1;
    }
    System.out.println(myList);
    }

}
Thomas P
  • 27
  • 3

1 Answers1

1

System.out.println(myList); is evaluated like myList.toString() and it will only print out the memory address which you are getting ([I@6d06d69c).

So, you should use Arrays.toString() to print array for per item;

System.out.println(Arrays.toString(myList));
lucky
  • 12,734
  • 4
  • 24
  • 46