java - 找不到 Integer.parseInt() 的符号错误

标签 java

我在以下代码中遇到错误:

import java.io.*;
import java.util.*;

public class Exercise1
{
    public static void main (String[] args) throws IOException
    {
        Scanner kbd = new Scanner(System.in);

        // declare ints for the int conversion of response, oddSum and evenSum
        final int intval = 0;
        int numb, sum=0;
        int evensum = 0, oddsum = 0;
        do
        {
            System.out.println("Enter a non-negative number: (or any negative number to quit) ");
            numb = Integer.parseInt(kbd.readLine());

            // read response into a int
            sum += numb;

            if (numb>=0&&numb/2 == 0) 
            {
                evensum += numb;
            }
            else
            {
                oddsum += numb;
            }
            System.out.print("number please");
            numb = Integer.parseInt(kbd.readLine());

            // if the int is zero or greater do the following
            //  if it's odd print it and add it to the oddSum
            //  BUT if it's even then print it and add it to the evenSum
        } while (numb >=intval);
        System.out.println("sum of even numbers is"+ evensum);
        System.out.println("sum of odd numbers is"+ oddsum);

        // print the sum of all the odds and the evens

    } // END main
} //EOF

我在这里收到“找不到符号”错误:

numb = Integer.parseInt(kbd.readLine());

这是为什么?

最佳答案

类型Scanner没有 readLine() 方法。

您是否想使用 nextLine()

关于java - 找不到 Integer.parseInt() 的符号错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18796895/

相关文章:

java - 即使密码和确认密码匹配,也会出现 Toast 消息

java - Selenium 示例代码 java 出现问题

java - Wicket:用自定义内容动态填充单元格

java - 使用一个 JComboBox 控制另一个 Jcombobox

java - 使用 Java 中的 TableSource、Table 或 DataSet 对象将 String 转换为 Double

java - 在java中编写异步调用序列的更好方法是什么?

java - Java 中从 double 转换为 int 时丢失精度

java - java while 循环中数字的除数

java - NullPointerException 启动 Android 应用程序

java - 如何 BatchUpdateSpreadsheetRequest google Sheets java api 中的特定工作表选项卡?