Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Scanner keyboard = new Scanner(System.in); // Declare an int variable. int age;

ID: 3628148 • Letter: S

Question

Scanner keyboard = new Scanner(System.in);

// Declare an int variable.
int age;

// Declare a double variable.
double gpa;

// Declare a String variable.
String nameEntered;

// Display a prompt message for the name.
System.out.println("Please enter your name:");

// Read in the name. (pg. 60 - 61)


// Display a prompt message for the age.
System.out.println("Please enter your age:");

// Read in the age. (pg. 42 - 43)
age = in.next();

Granted this is only part of the program, but for some reason I'm getting an error at age in.next(); -- cannot find symbol - variable in.

Why is this ? I am trying to get it to where the age reads as whatever they type in.

Explanation / Answer

please rate - thanks

Scanner keyboard = new Scanner(System.in);

// Declare an int variable.
int age;

// Declare a double variable.
double gpa;

// Declare a String variable.
String nameEntered;

// Display a prompt message for the name.
System.out.println("Please enter your name:");

// Read in the name. (pg. 60 - 61)


// Display a prompt message for the age.
System.out.println("Please enter your age:");

// Read in the age. (pg. 42 - 43)
age = in.next();

Granted this is only part of the program, but for some reason I'm getting an error at age in.next(); -- cannot find symbol - variable in.

Why is this ? I am trying to get it to where the age reads as whatever they type in.

change age=in.next()

to

age=keyboard.nextInt();

age is an integer so must be entered as an integer. next is used for a String

you've defined System.in as being associated with variable name keyboard so must say the age is the next integer in the keyboard buffer