public class javaLianxi { public static void main(String[] args) { int results[]={1,2,3,4,5,6,7,8,9}; for (int i = 0; i < results.length-1; i++) { for (int j = i+1; j < results.length; j++) { if (results[i]<results[j]) { int temp=results[i]; results[i]=results[j]; results[j]=temp; } } } for (int i = 0; i < results.length; i++) { System.out.println(results[i]); } }}
2 回答
阿旭_
TA贡献217条经验 获得超353个赞
public class javaLianxi { public static void main(String[] args) { int results[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; for (int i = 0; i < 2; i++) {//排两次即可 for (int j = i + 1; j < 3; j++) {//每次只排前三个数据 if (results[i] < results[j]) { int temp = results[i]; results[i] = results[j]; results[j] = temp; } } } for (int i = 0; i < results.length; i++) { System.out.println(results[i]); } } }
添加回答
举报
0/150
提交
取消