public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()){
if(list.size()>6){
break;
}
list.add(scanner.nextInt());
}
scanner.close();
boolean flag = true;
int m = 0;
int count = 0;
for (int i = 0; i < list.size(); i++) {
flag = true;
for (int j = 0; j < list.size() -i-1; j++) {
count++;
if(list.get(j) > list.get(j+1)){
//交换位置
int temp = list.get(j);
list.set(j,list.get(j+1));
list.set(j+1,temp);
flag = false;
}
}
//说明没有一次交换可以肯定已经排序完成
if(flag)
break;
}
System.out.printf("遍历%d次",count);
for (int i = 0; i < list.size(); i++) {
System.out.print(list.get(i)+"\t");
}
System.out.println();
}