【发布时间】:2015-11-22 20:20:59
【问题描述】:
好的,这是我的代码。我认为对数组中的这些数字进行排序应该可以正常工作。但是,每次我尝试运行它时,它所做的只是打印“[I@178af9c0”或一些奇怪的变化。我完全不知道该怎么做,如果你能给我任何帮助,我将不胜感激。非常感谢!!!
public class BubbleSort {
public void Print(){
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] BubbleSort = {3, 4, 1, 2};
int lengthOfArray = BubbleSort.length;
for (int i = 0; i < lengthOfArray - 1; i++){
for (int n = 1; n < lengthOfArray - i; n++){
if (BubbleSort[n - 1] > BubbleSort[n]){
Swap(i, n , BubbleSort);
}
}
}
System.out.println(BubbleSort.toString());
}
private static void Swap(int index1, int index2, int[] array) {
int temp;
temp = array[index1];
array[index1] = array[index2];
array[index2] = temp;
}
}
【问题讨论】:
-
另外,我的代码有什么明显的问题吗?
-
您正在尝试打印数组 System.out.println(BubbleSort.toString());您实际上应该打印数组中包含的项目 for(i=0;i
标签: java arrays sorting printing