在 Java 中找不到符号(扫描仪)
Cannot find symbol in Java (Scanner)
我是 Java 的新手,我很难学习基础知识。对于 class,我必须编写一个简单的 BMI 计算器,但不知何故我无法编译我的代码。
import java.util.Scanner;
public class BMI {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int weight;
int height;
double bmi;
System.out.println("Enter weight in kg: ");
weight = sc.NextInt();
System.out.println("Enter height in cm: ");
height = sc.NextInt;
bmi = weight / height*height;
System.out.println("Your BMI: " + bmi);
}
}
我不断收到以下错误消息:
Unknown:~ Philipp$ javac BMI.java
BMI.java:12: error: cannot find symbol
weight = sc.NextInt();
^
symbol: method NextInt()
location: variable sc of type Scanner
BMI.java:15: error: cannot find symbol
height = sc.NextInt;
^
symbol: variable NextInt
location: variable sc of type Scanner
2 errors
Unknown:~ Philipp$
我知道 "Cannot find symbol error" 通常是由拼写错误引起的,但我找不到任何错误。谁能告诉我怎么了?
weight = sc.NextInt();
应该是 weight = sc.nextInt();
有关 Java 区分大小写的更多信息,请参阅 this。
Java区分大小写。
weight = sc.nextInt();
不是
weight = sc.NextInt();
我是 Java 的新手,我很难学习基础知识。对于 class,我必须编写一个简单的 BMI 计算器,但不知何故我无法编译我的代码。
import java.util.Scanner;
public class BMI {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int weight;
int height;
double bmi;
System.out.println("Enter weight in kg: ");
weight = sc.NextInt();
System.out.println("Enter height in cm: ");
height = sc.NextInt;
bmi = weight / height*height;
System.out.println("Your BMI: " + bmi);
}
}
我不断收到以下错误消息:
Unknown:~ Philipp$ javac BMI.java
BMI.java:12: error: cannot find symbol
weight = sc.NextInt();
^
symbol: method NextInt()
location: variable sc of type Scanner
BMI.java:15: error: cannot find symbol
height = sc.NextInt;
^
symbol: variable NextInt
location: variable sc of type Scanner
2 errors
Unknown:~ Philipp$
我知道 "Cannot find symbol error" 通常是由拼写错误引起的,但我找不到任何错误。谁能告诉我怎么了?
weight = sc.NextInt();
应该是 weight = sc.nextInt();
有关 Java 区分大小写的更多信息,请参阅 this。
Java区分大小写。
weight = sc.nextInt();
不是
weight = sc.NextInt();