package com.yun.java.six;
import java.util.Scanner;
public class P5 {
public static void main(String[] args) {
// TODO Auto-generated method stub
/*
* created by sun 17/6/2
* 冒泡排序输出成绩
*/
System.out.println("请输入十个数字:");
Scanner input=new Scanner(System.in);
int[] scores=new int[10];//定义数组接收输入的成绩
for (int i = 0; i <scores.length; i++) {
System.out.println("请输入第"+(i+1)+"个人的成绩");
scores[i]=input.nextInt();
}
//冒泡排序重新排列成绩
System.out.println("排序后的成绩为:");
for (int i = 0; i < scores.length-1; i++) {
for (int j = 0; j < scores.length-1-i; j++) {
if (scores[j]>scores[j+1]) {
int num=scores[j];
scores[j]=scores[j+1];
scores[j+1]=num;
}
}
}
for (int i = 0; i < scores.length; i++) {
System.out.print(scores[i]+" ");
}
}
}
java中关于冒泡排序
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.