Using Console I/O
In this program, you will use the Scanner
class and
System.out
object to perform console I/O. In the main method,
you will:
- Read the user's First and Last name on a single line
- Read the user's age (in words) on a single line
- Display the following: Last, First, Age
For example, your output should look like the following:
Enter name (First Last): George Washington Enter age (in words): Two Hundred Eighty You Entered: Washington, George, Two Hundred Eighty
You can copy the following class skeleton into a new class file to start with.
// Import the Scanner class from the Java library here. public class ScannerInput { // Declare a Scanner reference variable and create // a Scanner object here. // Note that this reference will have class scope. public static void main( String[ ] args) { // Prompt the user to enter his first and last name // The names should be on a single line separated by a space // First Last // Prompt the user to enter his age (in words) // Display the names in the format // Last, First, Age } }