-1

I'm a rookie in Java. I just started it a day before. I don't know whether its a stupid question. Whatever , when i run the below codes , I got

[I@15db9742 as output.

public class array1 {
    public static void main(String[] args)
    {   
        int[] arr={1,2,3};
        System.out.println(arr);
    }
}

what does it mean ? When i create a char array as

char[] c={'a','b','c'};

i got the output as abc

System.out.println(c);

Why i didn't get the o/p as 123 in the above case... Eager to hear the answer...................

Stonz2
  • 6,306
  • 4
  • 44
  • 64
BabyboB
  • 55
  • 2
  • 9

3 Answers3

0

You are printing the array object directly. Hence you are seeing the String representation of object and not its content. Probably you want to do

System.out.println(Arrays.toString(arr));
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
0

You are printing the array wrongly.. do either

int[] arr={1,2,3};
         for (int i : arr) {
            System.out.println(i);

        }

or print it using the Arrays class

System.out.println(Arrays.toString(arr));

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
0

Following up on my comment. You want to print the content:

for(int i = 0; i< arr.length; i++){

System.out.println(arr[i]);
}
Perdomoff
  • 938
  • 2
  • 7
  • 26