7-5 sdut-JAVA-Exam Scores
分数 12
全屏浏览
切换布局
作者 马新娟
单位 山东理工大学
Write a program that requests an exam score and displays the corresponding letter grade using the information in the following table.If the exam score is less than 0 or more than 100,please display “Invalid exam score - a valid score is a whole number in the range 0 to 100." information.
Input Specification:
an exam score.
Output Specification:
displays the corresponding letter grade using the information in the following table.
Sample Input:
90
Sample Output:
Exam grade is A
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
栈限制
8192 KB
import java.util.Scanner; public class Main{ public static void main(String [] args) { Scanner sc=new Scanner(System.in); double n; n=sc.nextInt(); if(n>100||n<0) { System.out.println("Invalid exam score - a valid score is a whole number in the range 0 to 100."); } else if(n>=90&&n<=100) { System.out.println("Exam grade is A"); } else if(n>=80&&n<=89) { System.out.println("Exam grade is B"); } else if(n>=70&&n<=79) { System.out.println("Exam grade is C"); } else if(n>=60&&n<=69) { System.out.println("Exam grade is D"); } else if(n>=0&&n<=59) { System.out.println("Exam grade is F"); } } }