0
Why this code make this output? ( It ouputs [I@xxxxxxxx ) without any errors
Code: public class Main { public static void main(String[] args) { int[] map = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; System.out.println(map); } } I am using another compiler, not sololearn's playground
6 odpowiedzi
+ 1
You are printing the memory address of the array and it will give you the same result everytime you run it.
You can use the Arrays class and call the toString method and pass your array (map) as parameter:
System.out.println( Arrays.toString(map) );
You can also use an for-each loop if you want:
for(int elemens: map)
System.out.println(elemens);
0
I think it outputs the adress of the map?
Well map is defined as int[]
means map points to the computer adress of the first 1
Try to print map[0] to accesss first element
More to arrays in Java:
https://www.sololearn.com/learn/Java/2148/
0
The output is random every time
0
Try this:
System.out.println(map.toString);
At the last!
And I hope you know that you have made a uni dimensional array
0
Thanks For all answers!
0
you are welcome