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 block(s) would most effectively keep a sprite from moving off the screen?
Sonja [21]

The block most effectively keep a sprite from moving off the screen if if on edge, bounce. Hence option B is correct.

<h3>What is screen?</h3>

Screen is defined as a portable or stationary object that offers shelter, acts as a partition, etc., and often consists of a covered frame. Screening is defined as the procedure of locating or choosing individuals from a community according to one or more selection criteria.

The block will kept more perfectly if one of the edge there is bounce so that the box will not fall from the sprite.

Thus, the block most effectively keep a sprite from moving off the screen if if on edge, bounce. Hence option B is correct.

To learn more about screen, refer to the link below:

brainly.com/question/23902291

#SPJ1

8 0
1 year ago
You listened to a song on your computer. did you use hardware or software? explain.
scZoUnD [109]
Software, unless you planned on permanently downloading the Music Album or Song to your computer's Hard Drive. i.e, you would use whatever Music or Media player you have installed on your computer, and that simply counts as Software. 
4 0
3 years ago
A _____ is an electronic path over which data can travel.
vazorg [7]
A bus is an electrical path which data travels between the different components in an electronic device.                                                                      
5 0
4 years ago
.Visual Studio .NET’s ___________ feature displays all the members in a class
Alex

Answer:d)Intellisense

Explanation: Visual Studio.NET is the tool for the development of the application .Intellisense is the type of code that is found in the Visual Studio.NET which is used for the intelligent completion of text or code. The factors present in the Visual studio NET has are tracking of the values, increasing the understanding of code,presenting the class member etc.

Other options are incorrect because real time error checking is for the checking of the error raising at the time of execution, Quick info is for gaining data rapidly and outlined code are for display of the hierarchical structure of codes.Thus, the correct option is option(d).

3 0
3 years ago
How many times go you need to click the format painter button to apply copied formats to multiple paragraphs one right after the
Umnica [9.8K]
Double click would be enough
6 0
3 years ago
Read 2 more answers
Other questions:
  • To set up a slide show you should do all of the following except ______.
    9·1 answer
  • WILL MARK BRAINLIEST HELP
    8·2 answers
  • An information system is the entire set of __________, people, procedures, and networks that enable the use of information resou
    8·1 answer
  • Your bluetooth headset is waiting for another bluetooth device to locate its signal. what is this mode known as?'
    8·1 answer
  • What connectionless protocols are implemented at the lower layers of the OSI model, what is usually used to acknowledge that the
    5·2 answers
  • Items that are cut or copied are placed on the Clipboard.
    6·2 answers
  • <br> Help me please I need the correct answe
    10·1 answer
  • An end-user license agreement protects _____.
    7·1 answer
  • Hey everyone. I am so bored
    14·2 answers
  • How does an extranet work?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!