1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
max2010maxim [7]
3 years ago
14

Write a Java class called getName that prompts a user for their name and then displays "Hello, [name here]!" The flow should loo

k like the following:
What is your name? Randy Savage
Hello, Randy Savage!

If the user does not enter anything but presses Enter anyways, you should re-prompt for the user’s name. This flow should look like the following (note that there should be a space after any ? or :):

What is your name?
Please enter your name:
Please enter your name: Randy Savage
Hello, Randy Savage!
Computers and Technology
1 answer:
beks73 [17]3 years ago
3 0

Answer:

Following are the program in Java language

import java.util.*; // import package

class getName      // class getname

{

   public static void main(String[] args)  // main function

   {

         String str; // variable declaration

       Scanner scr1 = new Scanner(System.in); // create the instance of scanner class

       System.out.println("What is your name?");

     do  

       {

           System.out.print("Please enter your name: ");

           str = scr1.nextLine(); // Read the string by user  

           

           if(str.length() > 0) // check the condition  

           {  

               break;  // break the loop

           }

       }while(true); // iterating the loop

       System.out.println("Hello, " +str); // display the string in the proper format  

   }

}

Output:

What is your name?

Please enter your name: Randy Savage

Hello, Randy Savage

Explanation :

Following are the explanation of the java program

  • Create an instance of scanner class i.e "scr1".
  • Print the message on screen What is your name? by using System.out.println() method.
  • iterating the do-while loop for input in the "str" variable. If the user enters nothing then again asked for the input.
  • if(str.length() > 0) condition is used to terminate the loop if user input the string.
  • Finally, print the string in proper format which is mention in the question.

You might be interested in
What word can you spell with the letters e, e, a, m, g, t, and k?
SVETLANKA909090 [29]
Eat,get and Meg
all the words I can think of
8 0
4 years ago
What cell phone technology is the most popular in the united states?
Alchen [17]
IPhone and Android. ....
3 0
3 years ago
Read 2 more answers
Which of the following sets of data would be represented best in a histogram
PIT_PIT [208]
I’m sorrry but I can only answer this if I know the following. :(
8 0
4 years ago
Who was the first person to develop http the language in which servers and browsers communicate
Rudiy27
The answer would be Tim Berners- lee
6 0
3 years ago
Which layout manager constructor call would be best-suited to create a telephone handset GUI which has three rows of three keys
Snezhnost [94]

Answer:

The correct option : b. new GridLayout(4,3)

Explanation:

The total number of rows are 4 and total number of columns are 3.

So the total keys can be added is 4*3=12. This is suited for telephone keypad.

7 0
3 years ago
Other questions:
  • You can select a paragraph y using the ____key.
    10·1 answer
  • Mutual authentication for multiple services is also known as _______.
    12·1 answer
  • What is wrong, logically, with the following code? if (x > 10) System.out.println("Large"); else if (x > 6 && x &l
    11·1 answer
  • Anyone know the name of this font? and what site i can find it on so i can type it????
    8·1 answer
  • SONET: is a standard for optical transmission that currently operates at Terabit per second speeds is almost identical to the IT
    7·1 answer
  • An organization has hired a new remote workforce. Many new employees are reporting that they are unable to access the shared net
    11·1 answer
  • Many people in the United States will say that they have rights, however, the majority of those people do not know what those ri
    15·2 answers
  • Difference between authentication and authorization.
    15·1 answer
  • Which utilities are excellent examples of connectivity software, applications that enable you to determine if a connection can b
    8·1 answer
  • Suppose that you are given the following partial data segment. what value does idtype contain, in decimal?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!