簡體   English   中英

找不到Integer.parseInt()的符號錯誤

[英]Cannot find symbol error for Integer.parseInt()

我在以下代碼中遇到錯誤:

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()嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM