Question: in this program, you will learn how to enter data while the program is running by using the Scanner class enter the following command in
in this program, you will learn how to enter data while the program is running
by using the Scanner class
enter the following command in your code winder BEFORE the myAge class:
import java.util.Scanner
the Scanner class is needed for input, and Scanner is part of the java.util package
inside your myAge class, inbetween the curly brackets:
enter this command: Scanner input new ScannerSystemin;
this command makes input available to this class
next, enter a command that prompts the user to enter their age use the System.out.print command, with the prompt inside parentheses, and in quotes
next command: int age input.nextInt;
this command will pause the program, while it waits for input
final command: use a System.out.print command to display a sentence that says "You are age, which should confirm the age you input
save and run your program
to input your age, go to the output window and you should see your prompt
click after the prompt and key in your age; enter
sample program output: Enter your age:
You are
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
