package lianxi3; import java.util.Scanner; import java.util.Vector; public class TestScore { public static void main(String[] args) { // 1.从键盘输入学生成绩,输入负数结束 // 2.将学生成绩保存在Vector数组 Scanner s = new Scanner(System.in); System.out.println("从键盘输入学生成绩,输入负数结束"); Vector v = new Vector(); int max = 0; // while(s.nextInt()>0){ for (;;) { int score = s.nextInt(); if (score < 0) { break; } Integer score1 = score; v.addElement(score1); if (score > max) { max = score; } } // 3.找出最大值 System.out.println("max=" + max); // 4.遍历Vector数组,打印学生的成绩等级 for (int i = 0; i < v.size(); i++) { Integer in = (Integer) v.elementAt(i); int a = in; int degree = max - a; char level; if (degree <= 10) { level = 'A'; } else if (degree <= 20) { level = 'B'; } else if (degree <= 30) { level = 'C'; } else { level = 'D'; } System.out.println("学生成绩:" + a + "成绩等级:" + level); } } }