When you simply write System.out.println(*array*)
, the command will print the location in memory that stores the array.
If you are looking to print out the value stored in the array, you must specify the array index value you wish to print (note: array indexes begin at 0
and end at size-1
):
System.out.println(x[position]);
If you wish to print out the characters to the entire array, you must either use a for-loop
or an enhanced for-loop
:
for(int i = 0; i < x.length; i++){
System.out.println(x[i]);
}
The above code will create an int i
which acts as an index for the array. Every time the loop runs, the value stored at position i
will be printed out from the array x[]
. x.length
is used to make sure that int i
does not exceed the array size limit.