有一组学员的成绩{99,85,82,63,60},将它们按降序排
作者:
阿狸演绎 | 来源:发表于
2017-08-24 20:53 被阅读0次package inputArray;
import java.util.Arrays;
import java.util.Scanner;
public class inputArray {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a[] = new int[6];
a[0] = 99;
a[1] = 85;
a[2] = 82;
a[3] = 63;
a[4] = 60;
int index = a.length;
System.out.println("请输入成绩");
//scanner 用法
Scanner input = new Scanner(System.in);
//输入整数
int num = input.nextInt();
System.out.println("排序前");
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
for (int i = 0; i < a.length; i++) {
if (num>a[i]) {
//index 代替i
index = i;
break;
}else {
index = 5;
}
}
//元素后移
for (int j = a.length - 1; j > index; j--) {
//从index开始元素后移
a[j] = a[j-1];
}
//插入数据
a[index] = num;
System.out.println("插入的成绩是:"+a[index]);
System.out.println("插入后的成绩是");
//对数组进行升序排序
Arrays.sort(a);
for (int i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}
本文标题:有一组学员的成绩{99,85,82,63,60},将它们按降序排
本文链接:https://www.haomeiwen.com/subject/sdfydxtx.html
网友评论