package exer1;
import java.util.Scanner;
import java.util.Vector;
public class Student {
public static void main(String[] args) {
//1.实例化Scanner,用于键盘获取学生成绩
//2.创建Vector对象,:Vector v=new Vector
//3.通过for(;;)或者while(true)循环,给vector中添加数据
//3.1添加操作:v.addElement(Object obj)
//3.2当添加数是负数时跳出循环
//4.获取学生成绩的最大值
//5.遍历学生成绩,并与最大值做差,分等级
Scanner sc=new Scanner(System.in);
Vector<Integer> v=new Vector<>();
int max=0;
while(true) {
int score = sc.nextInt();
if(score>0) {
v.addElement(score);
if (score>max) {
max=score;
}
}
else {
break;
}
}
System.out.println(max);
System.out.println(v.size());
for(int i=0;i<v.size();i++) {
if (max-v.elementAt(i)<=10) {
System.out.println('A');
}
else if (max-v.elementAt(i)<=20) {
System.out.println('B');
}
else if (max-v.elementAt(i)<=30) {
System.out.println('C');
}
else {
System.out.println('D');
}
}
}
}
Vector练习
最新推荐文章于 2022-10-18 14:28:39 发布