5-1 成绩转换

百分制成绩转换为五级计分制时,90分以上为A,80~89分为B,70~79分为C,60~69分为D,0~59分为E。(建议使用switch语句完成)

输入格式:

测试有多组,每组输入1个整数score。处理到输入结束。

输出格式:

逐行输出百分制成绩score对应的字符等级。若score非法,输出"error!"

输入样例:

在这里给出一组输入。例如:

1
61
102

输出样例:

在这里给出相应的输出。例如:

E
D
error!

通过代码:

import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int s;
		while(true){
			s = sc.nextInt();
			if(s >= 90 && s <= 100){
				System.out.println("A");
			}
			else if (s >= 80 && s <= 89) {
				System.out.println("B");
			}
			else if (s >= 70 && s <= 79) {
				System.out.println("C");
			}
			else if (s >= 60 && s <= 99) {
				System.out.println("D");
			}
			else if (s >= 0 && s <= 59) {
				System.out.println("E");
			}
			else {
				System.out.println("error!");
			}
		}

	}
}

 

你可能感兴趣的:(Java期末考试题)