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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!