Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started