为什么x
变量的声明不起作用?它显示error : cannot find symbol
我是Java编程的新手
public static void CompareMark() {
double x;
System.out.print("Enter mark: \n");
x = scan.nextDouble();
if (x >= 0 && x <= 100) {
if (x >= 0 && x <= 49)
System.out.println("Grade:F");
else if (x >= 50 && x <= 59)
System.out.println("Grade:C");
else if (x >= 60 && x <= 74)
System.out.println("Grade:B");
else
System.out.println("Grade:A");
} else
System.out.println("Invalid marks");
}
答案 0 :(得分:0)
您尚未声明扫描:
Scanner scan = new Scanner(System.in);
答案 1 :(得分:0)
import java.util.Scanner;
public class Testing {
public static void main(String[] args) {
compareMark();
}
public static void compareMark() {
double x;
Scanner scan = new Scanner(System.in);
System.out.print("Enter mark: \n");
x = scan.nextDouble();
if (x >= 0 && x <= 100) {
if (x >= 0 && x <= 49)
System.out.println("Grade:F");
else if (x >= 50 && x <= 59)
System.out.println("Grade:C");
else if (x >= 60 && x <= 74)
System.out.println("Grade:B");
else
System.out.println("Grade:A");
} else
System.out.println("Invalid marks");
}
}