无法在原始类型int上调用nextint()

白兰地C Zoch

所以我在学习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

做什么?谢谢。

duffy356

int是原始值。它不是对象,也没有方法。

可能你想做

answer = input.nextInt();

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法在原始类型int上调用toString()

无法在给定类型的类型定义上调用方法

无法在基本类型boolean上调用equals

无法在原始类型void上调用forEach((<no type> de)-> {})

无法在原始类型void上调用sendKeys(String)

处理/ java:无法在数组类型boolean []上调用length()

Java 8-无法在数组类型Enum []上调用stream()

Java 8流获取无法在原始类型void上调用映射

无法在基本类型float上调用mult(float)

无法在数组类型(类)MitarbeiterListe []上调用方法getSize()

无法在数组类型int [] []上调用splice(int,int)

可以在Strings和Int上调用的函数。模糊类型变量问题

转换.c ++后,在char类型的原始缓冲区上调用delete

在Dart中,无法使用int调用(int)=> String类型的函数

无法在基本类型char上调用equals(char)

在Java中,如何在泛型类型的实例上调用getClass时避免原始类型?

无法在原始类型int上调用equals(String)

无法在原始类型int上调用findViewById(int)

尝试在空对象引用上调用虚拟方法'int java.util.Random.nextInt(int)'[Android]

无法在CustomListAdapter上调用notifyDataSetChanged

Java错误:无法在原始类型double上调用size()

无法将类型“ Int”的值转换为原始类型“ DarwinBoolean”

无法在受其他协议限制的通用类型上调用协议方法

我得到:无法在原始类型int上调用length()

得到此错误“无法在数组类型String []上调用set(int,String)”

如何解决流程中的“无法在对象类型上调用构造函数”错误?

无法调用 isSelected(); 在原始类型布尔值上

无法在位上调用方法

无法对原始类型 int 调用 contains(int)