+-

所以我正在学习 Java,也许他没有很好地解释扫描仪的工作方式和限制,或者我正在寻找一些愚蠢的东西……但是我在answer = answer.nextInt();我没有得到这个炸弹的错误,但它的使用方式几乎相同……
码:
Scanner yesNo = new Scanner(System.in);
Scanner input = new Scanner(System.in);
//
//answer auto set to no. goes to first if, then asks for confirmation,
// then check answer again and go to if, else if or else.
//
int answer = 0;
while (answer != 1)
if (answer == 0) {
System.out.println("In how many seconds should we detonate?");
int bomb = input.nextInt();
//this number will be used later in else if (answer == 1)
System.out.println("Is " + bomb + " seconds correct? 1 for yes, 0 for no");
answer = answer.nextInt();
//error above "Cannot invoke nextint() on the primitive type int"
//Need this to grab a number from user to assign a new value to answer
做什么?谢谢.
最佳答案
int是原始值.它不是Object,也没有方法.
可能你想做
answer = input.nextInt();
点击查看更多相关文章
转载注明原文:java – 无法在基本类型int上调用nextint() - 乐贴网