Java程序计算学生成绩
以下程序接受用户的平均值,计算成绩并打印出来。
示例
public class CalculateStudentGrades {public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter average of your marks (less than 100)::");
int average = sc.nextInt();
char grade;
if(average>=80){
grade = 'A';
}else if(average>=60 && average<80){
grade = 'B';
}
else if(average>=40 && average<60){
grade = 'C';
}
else {
grade = 'D';
}
switch(grade) {
case 'A' :
System.out.println("Excellent!");
break;
case 'B' :
case 'C' :
System.out.println("Well done");
break;
case 'D' :
System.out.println("You passed");
case 'F' :
System.out.println("Better try again");
break;
default :
System.out.println("Invalid grade");
}
System.out.println("Your grade is " + grade);
}
}
输出结果
Enter average of your marks (less than 100)::59
Well done
Your grade is C
以上是 Java程序计算学生成绩 的全部内容, 来源链接: utcz.com/z/316998.html