你好Stackoverflowers的伙伴们,
我如何打印出numbersArray,以便我可以看到数字?
当我输入numbersArray时,它向我显示:
[I@677327b6
[I@677327b6
感谢您的时间和帮助!
package AlgoExercises;
public class InsertionSort {
static int[] numbersArray = { 5, 2, 4, 6, 1, 3 };
static void swap(int a, int b) {
int temp = a;
a = b;
b = temp;
// a and b are copies of the original values.
// The changes we made here won't be visible to the caller.
}
static void insertionSort(int[] numbersArray) {
for (int i = 1; i < numbersArray.length; i++) {
int j = i;
while ((j > 0) && (numbersArray[j] < numbersArray[j - 1])) {
swap(numbersArray[j], numbersArray[j - 1]);
j = j - 1;
System.out.println(numbersArray);
}
}
}
public static void main(String args[]) {
insertionSort(numbersArray);
}
}发布于 2016-01-14 18:57:12
要打印数组,请使用java.lang.Arrays.toString()方法:
System.out.println(Arrays.toString(numbersArray));发布于 2016-01-14 18:57:12
System.out.println(numbersArray);您打印的是数组而不是值。您应该通过numbersArrayi打印值
https://stackoverflow.com/questions/34787774
复制相似问题