Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm getting an error in the following code:

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

I'm getting the "cannot find symbol" error here:

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

Why is this?

share|improve this question
Please print the actual error message, not just an excerpt. – chrylis 11 mins ago
How about reading some documentation? docs.oracle.com/javase/7/docs/api/java/util/Scanner.html – Matt Ball 7 mins ago

1 Answer

The type Scanner does not have a readLine() method.

Did you mean to use nextLine()?

share|improve this answer
If you use an IDE, it will catch these things for you and usually offer helpful suggestions. – chrylis 9 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.