目前正在努力理解我的错误消息的含义。我知道它不喜欢我从浮点数变为整数,但我该如何解决呢?
import java.util.Scanner;
public class gradeAverage {
public static void main (String [] args) {
Scanner sc = new Scanner(System.in);
System.out.println("First test score?");
float test1 = sc.nextInt();
System.out.println("Second test score?");
float test2 = sc.nextInt();
System.out.println("Third test score?");
float test3 = sc.nextInt();
float testAverage = (test1 + test2 + test3)/3;
System.out.println("Your test average is " + testAverage + ".");
switch(testAverage) {
case(97.5 <= testAverage <= 100):
System.out.println("Grade is an A+");
break;
case(93.5 <= testAverage <= 97.49):
System.out.println("Grade is an A");
break;
case(89.5 <= testAverage <= 93.49):
System.out.println("Grade is an A-");
default:
System.out.println("Grade is below an A-");
}
}
}
错误
gradeAverage.java:13: error: incompatible types: possible lossy conversion from float to int
switch(testAverage) {
^
gradeAverage.java:14: error: bad operand types for binary operator '<='
case(97.5 <= testAverage <= 100):
^
first type: boolean
second type: int
2 errors
月关宝盒
富国沪深
相关分类