我根据书中的说明编写了一个关于扫描仪的程序,但它无法编译。由eclipse提供的解释是nextint()未定义。我不知道如何定义nextint()。任何人都可以帮忙我呢?
import java.util.Scanner;
public class ReadTwoNums{
public static void main(String[] args){
int num1,num2,sum;
Scanner keyboard=new Scanner(System.in);
System.out.print("Input the first the integer");
num1=keyboard.nextint();
System.out.print("Input the second the integer");
double dollars=keyboard.nextDouble();
num2=keyboard.nextint();
sum=num1+num2;
System.out.println("The sum is"+sum);
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method nextint() is undefined for the type Scanner
The method nextint() is undefined for the type Scanner
at exercise.ReadTwoNums.main(ReadTwoNums.java:8)
答案 0 :(得分:-1)
nextInt()区分大小写
尝试keyboard.nextInt();
答案 1 :(得分:-1)
Java区分大小写
它应该是Keyboard.nextInt()
而不是nextint()。就像你在keyboard.nextDouble()
import java.util.Scanner;
public class ReadTwoNums{
public static void main(String[] args){
int num1,num2,sum;
Scanner keyboard=new Scanner(System.in);
System.out.print("Input the first the integer");
num1=keyboard.nextInt();
System.out.print("Input the second the integer");
double dollars=keyboard.nextDouble();
num2=keyboard.nextInt();
sum=num1+num2;
System.out.println("The sum is "+sum);
}
}//end of class ReadTwoNums