Reputation: 413
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
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