Java数组打印出奇异数和文本 [英] Java arrays printing out weird numbers, and text
问题描述
我是新来编程。我敢肯定,这个问题的答案就在那里,但我不知道该怎么寻找。
I'm new to programming. I'm sure the answer for this question is out there, but I have no idea what to search for.
所以,嗯。好吧,我会正确的去了。
so um. ok, i'll go right to it.
下面是我的code:
int[] arr;
arr = new int[5];
arr[0] = 20;
arr[1] = 50;
arr[2] = 40;
arr[3] = 60;
arr[4] = 100;
System.out.println(arr);
}
}
&编译放大器;工作正常。这只是从CMD的输出,我是晕的。
Compiles & works fine. It's just the output from CMD that i'm dizzy about.
这是输出: [I @ 3e25a5
我希望他们能够从列表(ARR),而不是重新present完全一样的号码。我如何做到这一点?
I want them to represent the exact same numbers from the list (arr) instead. How do I make that happen?
推荐答案
每个对象都有一个toString()方法,默认的方法是显示对象的类名重presentation,然后@后面的哈希code。所以你看到的是一个int数组的默认的toString()再presentation。要打印数组中的数据,可以使用
Every object has a toString() method, and the default method is to display the object's class name representation, then "@" followed by its hashcode. So what you're seeing is the default toString() representation of an int array. To print the data in the array, you can use
System.out.println(java.util.Arrays.toString(arr));
或者你也可以通过与一个for循环数组环路其他人张贴在这个线程。
Or you can loop through the array with a for loop as others have posted in this thread.
这篇关于Java数组打印出奇异数和文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!