0

I'm creating a method for a homework problem that returns the highest value in an array. I'm using a for
loop to input the numbers into the array. Here is what the input code looks like.

int[] array = new int [n];
    for(i=0;i<array.length;i++){
        array[i]=sc.nextInt();
        System.out.println(array);}

When i run the program to try and see if there's anything wrong as a I go along I notice the array not returning the value I input into it. For example putting the number 12 it returns [I@6c80d028. I'm pretty new to java so I don't really know what's going on with the input. Is there any thing that can be done?

ajg55
  • 17
  • 5

2 Answers2

1

Please use:

System.out.println(Arrays.toString(array));
ajay.patel
  • 1,957
  • 12
  • 15
1

Please do this

System.out.println(array[i]); 

or

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

when you

System.out.println(array);

It prints the address and not the value hence you see a junk characters / not expected value.

StackFlowed
  • 6,664
  • 1
  • 29
  • 45