gpt4 book ai didi

java - 为什么我的 if/else if 语句不起作用?

转载 作者:行者123 更新时间:2023-12-02 05:18:34 25 4
gpt4 key购买 nike

我在这里查看了所有其他类似的线程,但我仍然无法弄清楚为什么我的程序无论如何都只打印 A 或 A- 。请解释我做错了什么以及如何改变它。谢谢!

import static java.lang.System.*;
import java.util.Scanner;
public class Grading
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

int grade;
out.println("Please enter your grade to be evaluated: ");
grade = sc.nextInt();

if(grade >= 93)
out.println("A");
else if(grade >= 90 && grade <= 92)
out.println("A-");
else if(grade >= 87 && grade <= 89)
out.println("B+");
else if(grade >= 83 && grade <= 86)
out.println("B");
else if(grade >= 80 && grade <= 82)
out.println("B-");
else if(grade >= 77 && grade <= 79)
out.println("C+");
else if(grade > =73 && grade <= 76)
out.println("C");
else if(grade >= 70 && grade <= 72)
out.println("C-");
else if(grade >= 67 && grade <= 69)
out.println("D+");
else if(grade >= 63 && grade <= 66)
out.println("D");
else if(grade >= 60 && grade <= 62)
out.println("D-");
else if(grade < 60)
out.println("F");

}
}

最佳答案

你的程序运行得很好。只需更改

else if(grade > =73 && grade <= 76) 

else if(grade >=73 && grade <= 76)

关于java - 为什么我的 if/else if 语句不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26694806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com