使用if-else语句进行分级 import java.util.Scanner; 公营班级{ 公共静态void main(字符串参数[]){ 扫描仪输入=新扫描仪(System.in); 双重否定; 系统输出打印(“请输入您的注册会计师:”); 否=input.nextDouble(); 如果(2.00

使用if-else语句进行分级 import java.util.Scanner; 公营班级{ 公共静态void main(字符串参数[]){ 扫描仪输入=新扫描仪(System.in); 双重否定; 系统输出打印(“请输入您的注册会计师:”); 否=input.nextDouble(); 如果(2.00,java,javascript,if-statement,Java,Javascript,If Statement,它应该。因为第四类由以下lodic给出 import java.util.Scanner; public class grade { public static void main(String args[]) { Scanner input = new Scanner(System.in); double no; System.out.print("Please enter your CPA: "); no = input.nextDouble(); if (2.00

它应该。因为
第四类
由以下lodic给出

import java.util.Scanner;

public class grade   {
public static void main(String args[])       {

Scanner input = new Scanner(System.in);

double no;
System.out.print("Please enter your CPA: ");

no = input.nextDouble();

if (2.00<=no)//2.00<=CPA<= 2.49
System.out.println("forth class");

else if (2.50<=no)//2.50<=CPA<=2.99
System.out.println("third class");

else if (3.00<=no)//3.00<=CPA<=3.74
System.out.println("second class");

else if (3.74<=no)//(no>=3.75)
System.out.println("first class");

else
     System.out.println("You did not follow the order.");

     }  }

因为3.5和4大于2,所以你得到了第四个类,你最好在这里给我们一个switch语句。

你的第一个条件
if(2.00你只需要在你的if条件中添加&&(and),就像

if (3.74 <= no) {
    System.out.println("first class");
} else if (3.00 <= no) {
    System.out.println("second class");
} else if (2.50 <= no) {
    System.out.println("third class");
} else if (2.00 <= no) {
    System.out.println("forth class");
} else {
    System.out.println("You did not follow the order.");
}

if(2.00这是一个简单的
if else
语句问题。您忘记在语句中设置边界(范围值)。

您得到了预期的输出,因为您当前只检查它是否超过某个数字,请尝试交换顺序,并在每个语句中添加类似的内容:

if (2.00<=no && no < 2.50)
 System.out.println("forth class");

如果(no>=2.00&&no您必须定义上限和下限

if (no>=2.00 && no<=2.49)//2.00<=CPA<= 2.49
System.out.println("forth class");

else if (no>=2.50 && no<=2.99)//2.50<=CPA<=2.99
System.out.println("third class");

else if (no>=3.00 && no<=3.74)//3.00<=CPA<=3.74
System.out.println("second class");

else if (no>=3.75)//(no>=3.75)
System.out.println("first class");

else
System.out.println("You did not follow the order.");

if(3.74 no&&3.00 no&&2.50 no&&2.00(3.00例如,if(no>=3.00&&no<3.74){//头等舱或其他什么东西}在第一次操作中,你将结果限制在大于3.00和/或必须小于3.746个答案,并且对一个基本逻辑问题没有否决票。这就是为什么我们不能有好东西。我只是一个初学者:D@JhKaizI知道,但是想想逻辑,你可以自己解决它,没有这些帮助,你比你想象的要好。伙计。今天是祝您愉快,无需投票@ivy_lynx xD!@user3455084如果这对您有帮助,请选择它作为正确答案!
if (no>=2.00 && no<=2.49)//2.00<=CPA<= 2.49
System.out.println("forth class");

else if (no>=2.50 && no<=2.99)//2.50<=CPA<=2.99
System.out.println("third class");

else if (no>=3.00 && no<=3.74)//3.00<=CPA<=3.74
System.out.println("second class");

else if (no>=3.75)//(no>=3.75)
System.out.println("first class");

else
System.out.println("You did not follow the order.");
if (3.74 <= no) {
    System.out.println("first class");
} else if (3.74 > no && 3.00 <= no) {
    System.out.println("second class");
} else if (3.00 > no && 2.50 <= no) {  
   System.out.println("third class");
} else if (2.50 > no && 2.00 <= no) {
   System.out.println("forth class");
} else {
   System.out.println("You did not follow the order.");
}