我想排序我的数组,但出于某种原因,它打印出第二次 - 排序结果之前?排序后排列两次阵列
int []arrayLoterry= new int[50];
String output="";
for(int i=0;i<arrayLoterry.length;i++){
arrayLoterry[i]=(int) Math.floor(Math.random()*49)+i;
output+=arrayLoterry[i]+" ";
if(i%10==9){
output+="\n";
}
}
System.out.println(output);
/************WHERE IT STARTS SORTING****************************/
int temp;
for(int i=0;i<arrayLoterry.length;i++){
for(int j=i+1;j<arrayLoterry.length;j++){
if(arrayLoterry[i]>arrayLoterry[j]){
temp= arrayLoterry[j];
arrayLoterry[j]=arrayLoterry[i];
arrayLoterry[i]=temp;
}
}
}
System.out.println();
for(int j=0;j<arrayLoterry.length;j++){
output+=arrayLoterry[j]+" ";
if(j%10==9){
output+="\n";
}
}
System.out.println(output);
什么这给(由编辑简体):
5 3 2 1
7 9 4 0
5 3 2 1
7 9 4 0
0 1 2 3
4 5 7 9
为什么它打印出来后,我再次做排序?
提示下一次:您的输出也是** text **。创建显示它的屏幕截图没有任何意义。只需使用该文本进行复制/粘贴即可。我自由地编辑你的问题,以显示你的问题 – GhostCat