public static void main(String[] args) {
int[] my_Numbers= {1789, 2035, 1899, 1456, 2013,
1458, 2458, 1254, 1472, 2365,
1456, 2165, 1457, 2456};
for(int i=0; i < my_Numbers.length;){
if (Integer.compare(my_Numbers[i],my_Numbers[(i+1)])==1) {
int x = my_Numbers[i];
my_Numbers[i] = my_Numbers[i+1];
my_Numbers[i+1] = x;
i=0;
}else {i++;}
}
String result= my_Numbers.toString();
System.out.println(result);
}
答案 0 :(得分:0)
尝试一下:
val
答案 1 :(得分:-1)
首先在执行(i + 1)之前添加if条件,因为当我成为最后一个元素时,它将给您arrayindexoutof绑定异常。