Question: undefined 2- Getting user input To get input from user, you must first import a library to enable you to do this. To import a
undefined
2- Getting user input To get input from user, you must first import a library to enable you to do this. To import a library, go to the very beginning of your java file, go to the line right after the package line and right the following: import java.util.Scanner; java.util.Scanner is the name of the library we need. After importing your library, write the following inside your main method Scanner input = new Scanner(System.in); -- Do not worry if you do not fully understand the structure of the previous statement, you will be able to understand throughout the course. To take integer input from the user you will write the following inside your main method: int myNumber=input.nextInt(); to take double input you will do the following: double myNumber=input.nextDouble(); to take a string, String myName=input.next(); To take a full line, String myLine=input.nextLine(); Create a small program that asks the user to enter name and age and the program will display them back
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
