package zh.codegym.task.task06.task0622;
import java.util.ArrayList;
/*
升序数字
*/
public class Solution {
public static void main(String[] args) throws Exception {
java.util.Scanner s = new java.util.Scanner(System.in);
ArrayList<Integer> li = new ArrayList<Integer>();
//在此编写你的代码
li.add(s.nextInt());
li.add(s.nextInt());
li.add(s.nextInt());
li.add(s.nextInt());
li.add(s.nextInt());
for (int i = 1; i < li.size(); i++) {
for (int j = i-1; j >= 0; j--) {
if (li.get(j+1) < li.get(j)) {
int tempi = li.get(j+1);
int tempj = li.get(j);
li.set(j, tempi);
li.set(j+1, tempj);
}
}
}
for (int i : li) {
System.out.println(i);
}
}
}
提供一个简单的冒泡排序吧,尽量不要用sort()方法
正在讨论
评论 (1)
- 受欢迎
- 新
- 旧
你必须先登录才能发表评论
Gellert Varga
30 十二月 2020, 22:15
I think it works well (for fixed five items).
But to share complete good solutions is not allowed - the others just copy this, and they not will thinking about how to solve the problem...
0