我是Java的新手,我很难学习基础知识。对于课程,我必须编写一个简单的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$
我知道“无法找到符号错误”通常是拼写错误引发的,但我找不到任何错误。谁能告诉我什么是错的?
答案 0 :(得分:1)
weight = sc.NextInt();
应为weight = sc.nextInt();
有关Java的区分大小写特性的更多信息,请参阅this。
答案 1 :(得分:0)
Java区分大小写。
weight = sc.nextInt();
不是
weight = sc.NextInt();