Question: /* This program illustrates the use of a string variable, and the use of a scanner object It asks the user for their name The
/* This program illustrates the use of a string variable, and the use of a scanner object It asks the user for their name The user enters name via keyboard (KBD) and presses enter then the program prints "Greetings name" */
//have to import to find scanner class import java.util.Scanner;
class nameInOut { public static void main (String[] args) { // declare a scanner object for input Scanner scan = new Scanner( System.in ); // declare a string variable to take the name from the KBD String name;
//print a message to ask the user for their name System.out.println("Enter your name:");
//get next line (name) from KBD & put it in string var, name name = scan.nextLine();
//output the greetings message and the name System.out.println("Greetings " + name + "!"); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
