Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java If else范围链检查未按预期执行_Java_Android_If Statement_Conditional Statements_Relational Operators - Fatal编程技术网

Java If else范围链检查未按预期执行

Java If else范围链检查未按预期执行,java,android,if-statement,conditional-statements,relational-operators,Java,Android,If Statement,Conditional Statements,Relational Operators,当我传递某个浮点值与我的条件语句进行比较时,它总是执行else部分 有些变量的值为: float total = 74.67 ; String grade = "", point = ""; 有了这些值,我想这样做: if(total>=80){ grade = "A+"; point = "4.00"; }else if(total<=79 && total>=75){ grade = "A";

当我传递某个浮点值与我的条件语句进行比较时,它总是执行else部分

有些变量的值为:

float total = 74.67 ; 
String grade = "", point = "";
有了这些值,我想这样做:

if(total>=80){
        grade = "A+";
        point = "4.00";
}else if(total<=79 && total>=75){
        grade = "A";
        point = "3.75";
}else if(total>=70 && total<=74) {
        grade = "A-";
        point = "3.50";
}else if(total<=65 && total>=69){
        grade = "B+";
        point = "3.25";
}else if(total<=64 && total>=60){
        grade = "B";
        point = "3.00";
}else if (total<=59 && total>=55){
        grade = "B-";
        point = "2.75";
}else if (total<=54 && total>=50){
        grade = "C+";
        point = "2.50";
}else if(total<=49 && total>=45){
        grade = "C";
        point = "2.25";
}else if (total<=44 && total>=40){
        grade = "D";
        point = "2.00";
}else {
        grade = "F";
        point = "0.00";
}
如果(总数>=80){
评级=“A+”;
point=“4.00”;
}否则,如果(总计=75){
等级=“A”;
point=“3.75”;

}否则,如果(总计>=70&&total=70&&total您正在检查79-75和70-74之间的值,但在74-75之间缺少一个零件

。。。
如果(总数=75){
等级=“A”;
point=“3.75”;
}否则如果(总计>=70&&total=70&&total=70&&total=80){
评级=“A+”;
point=“4.00”;
}否则,如果(总计=75){
等级=“A”;
point=“3.75”;

}否则如果(总数>=70&&total=65&&total我想你应该试试

如果要在“A级”中打印此值,请尝试

if(total<80 && total>74){
    grade = "A";
    point = "3.75";
}else if(total>=70 && total<=74) {
    grade = "A-";
    point = "3.50";
}
 if(total<80 && total>=75){
    grade = "A";
    point = "3.75";
}else if(total>=70 && total<75) {
    grade = "A-";
    point = "3.50";
}
if(总计74){
等级=“A”;
point=“3.75”;

}else如果(total>=70&&total=70&&total这里没有一个条件得到满足,这就是它执行else部分的原因

但这不仅会发生在74.67上,还会发生在许多其他值上 那么你的情况应该是这样的,

if(总计>81){
评级=“A+”;
point=“4.00”;
}否则如果(总计76){
等级=“A”;
point=“3.75”;

}否则如果(total>71&&total66&&total66&&total66你为什么不试着调试它?我不知道怎么做你认为
74.67就像@ADM说的,你需要学习调试你的应用程序。查看详细信息你的代码的主要问题是你在比较int值而不是float值。所以,每次你在比较之间有一个值,例如74->75,它总是会比较的s落在
的其他部分上。
 if(total<80 && total>=75){
    grade = "A";
    point = "3.75";
}else if(total>=70 && total<75) {
    grade = "A-";
    point = "3.50";
}
if(total>81){
        grade = "A+";
        point = "4.00";
    }else if(total<80 && total>76){
        grade = "A";
        point = "3.75";
    }else if(total>71 && total<75) {
        grade = "A-";
        point = "3.50";
    }else if(total>66 && total<70){ // here was another mistake
        grade = "B+";
        point = "3.25";
    }else if(total<65 && total>61){
        grade = "B";
        point = "3.00";
    }else if (total<60 && total>56){
        grade = "B-";
        point = "2.75";
    }else if (total<55 && total>51){
        grade = "C+";
        point = "2.50";
    }else if(total<50 && total>46){
        grade = "C";
        point = "2.25";
    }else if (total<45 && total>41){
        grade = "D";
        point = "2.00";
    } else {
        grade = "F";
        point = "0.00";
    }