gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 18:43:45 30 4
gpt4 key购买 nike

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

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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com