所以我在学习Java,也许他对扫描仪的工作原理和限制没有足够的解释,或者我在寻找一些愚蠢的东西……但是我遇到了一个错误,answer = answer.nextInt();
我没有得到这个错误,bomb
但是它的使用方式几乎相同...
码:
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是原始值。它不是对象,也没有方法。
可能你想做
answer = input.nextInt();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句