Hi guys

Whenever I run this program, some weird characters like: ( [I@1f436f5 ) appear.

int[] list= new int[3];
        Scanner scan = new Scanner(System.in);
        for(int i=0;i<list.length;i++){
            System.out.println("Enter a number:");
            list[i] += scan.nextInt();
        }
        System.out.print(list);

How can I fix this? It is supposed to print the numbers entered from the user and not these characters.

Thanks.

That's what happens when you print an object that doesn't have its own toString() method defined. It's the class name followed by its hash code.
To print the contents of an array, convert it to a String by using Arrays.toString(list)

or print the seperate values of the array.

Why don't you just print it using an iteration? That way you don't have to convert it to a string.
I guess what you're doing now, is printing the adress of 'list', that's what causes those 'weird characters'

Why don't you just print it using an iteration? That way you don't have to convert it to a string.
I guess what you're doing now, is printing the adress of 'list', that's what causes those 'weird characters'

because prinltln(Arrays.toString(list)); is shorter and easier than coding a loop.

And it's a popular misunderstanding that the hex in Object's toString is an address. It's actually the hash of the Object, which may or may not be its address. Check out the API doc for Object for more details.

You're right indeed :)
I always do printing lists with an iteration loop. It's longer indeed, but works just fine. Tried to do it your way, and I'm having the same problem..

Tried to do it your way, and I'm having the same problem..

That's strange. Try this:

int[] list = {1,2,3};
System.out.println(Arrays.toString(list));

now what is different about your case that "has the same problem"?

Fixed it, stupid mistake..
Forgot to add

import java.util.Arrays;

Then used the code you gave

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

and now it works :)

Thanks!

@OP:
For future reference and to clarify, the weird symbols are actually: The class name followed by an "at" sign (@) and the unsigned hexadecimal representation of the hash code

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.