Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does Java give this output?

When trying to run the following code:

public static void main(String[] args) {
    int num_amount = 7;
    int[] num_array = {3, 4, 1, 1, 2, 12, 1};
    System.out.println(num_array.length);
    for (int i = 0; i < num_array.length; i++) {
        num_array[i] = 0;
        System.out.println(num_array);
    }
}

This is the output i get:

7
[I@ea30797
[I@ea30797
[I@ea30797
[I@ea30797
[I@ea30797
[I@ea30797
[I@ea30797

Has anyone ever experienced this "unusual" result? If so, what solution did you try out? Thanks in advance.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you want to print the contents of an array you can use Arrays.toString.

System.out.println(Arrays.toString(num_array));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading