ultra99
ultra99

Reputation: 413

error: cannot find symbol; symbol: variable keyBoard

I have this code and tried to compile it. But it gave me

error: cannot find symbol

anotherEntry = keyBoard.nextInt();

symbol: variable keyBoard

location: class DemoVariables3

Any clue why?

Code:

import java.util.Scanner;

public class DemoVariables3
{
 public static void main(String[] args)
  {
     int entry;
     int anotherEntry;
     System.out.print("Enter another integer ");
     anotherEntry = keyBoard.nextInt();
     System.out.print("The other entry is ");
     System.out.println(anotherEntry);
     System.out.println(entry + "plus" +
    anotherEntry + "is" + (entry + anotherEntry));
  }
}

Upvotes: 0

Views: 5740

Answers (1)

user142162
user142162

Reputation:

You need to create a variable named keyBoard and assign it to a new Scanner object before you try using the variable keyBoard:

Scanner keyBoard = new Scanner(System.in);

Upvotes: 1

Related Questions