-2

I have a ten spot array in my code, which is user inputted.

for (int i = 0; i < arraya.length; i++){
     arraya[i] = scan.nextInt();
}

After entering

2, 4, 53, 2, 3, 46, 45, 5, 4, 3

the array that was printed read

[I@86b012

How do I fix this?

singhakash
  • 7,891
  • 6
  • 31
  • 65
GDaniels
  • 31
  • 5

2 Answers2

2

You might be printing array like

System.out.print(arraya); which internally calls arraya.toString() and gives [I@86b012 .

  • [I - is a class name
  • [ - an single-dimensional array
  • @ - joins the string together
  • 86b012 - the hashcode of the object

Source

you have to do

for (int i = 0; i < arraya.length; i++){
     System.out.print(arraya[i]+" ");
}

or

System.out.println(java.util.Arrays.toString(arraya)); 

Demo

Community
  • 1
  • 1
singhakash
  • 7,891
  • 6
  • 31
  • 65
0

Every java object has a toString() method, and the default method is to display the object's class name representation, then "@" followed by its hashcode. What you're seeing is the default toString() representation of an int array. To print the actual data in the array, you can:

System.out.println(java.util.Arrays.toString(arraya));

Or you can loop through the array like other's have suggested

benscabbia
  • 17,592
  • 13
  • 51
  • 62