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
2. What are the 3 Alternative software programs that can be used if you don’t have the Microsoft Office programs?
Andrews [41]

Answer:

OpenOffice, Polaris Office, LibreOffice

7 0
3 years ago
Read 2 more answers
What are some fun games to play on you phone?
musickatia [10]
Madden,clash of clans
8 0
3 years ago
Read 2 more answers
Create Python program code that will use a for loop to ask the user to enterfourintegers. Itwillcount how many of the integers a
aleksandrvk [35]

Answer:

is_even = 0

int_numbers = []

for n in range(4):

n = int(input('press any four integer numbers')

int_numbers.append(n)

for n in int_numbers:

if n%2==0:

print(n, 'integer is even')

is_even+= 1

else:

print(n, 'integer is odd')

print('Total even numbers =', is_even)

Explanation:

is_even = 0 (initiates a counter to record the number of even integers).

int_numbers creates a list to store the inputs entered by the user.

int(input()) : allows users to enter an integer number

int_numbers.append(n) : adds user input to list list variable created.

n%==2 : checks if entered digit leaves a remainder of 0 when divided by 2; hence an even number

is_even+= 1: counter updates by 1 for every even number confirmed.

7 0
3 years ago
Svieta is making a chart of the hours that different employees have put into a team project at work. What formula would AutoSum
grin007 [14]

Answer:

Its =SUM(B2:B7)

The worksheet range B2:B7 means B2, B3, B3, B4.....,B7.

And for finding the sum of all these cells we need to make use of the SUM, but we need to place the = sign at first, and then all aggregate function will be listed in dropdown, and then we need to pick the SUM from there, and mention the worksheet range as above to define the cells which we want to include in the formula.  

Explanation:

The answer does not require any further explanation.

8 0
3 years ago
todd’s manager had asked him to write a report on ways to increase safety in the warehouse Todda you to Internet to research sta
wariber [46]
<span>The answer is : He likely did not cite his research, and committed plagiarism.  </span>Todd's manager has asked him to write a report on ways to increase safety in the warehouse. Todd used the Internet to research statistics and recommendations for improving safety in the workplace. He feels like he pulled together a really strong document and that his manager will be pleased. However, when he is called into his manager's office, his manager is concerned and tells him that he has been unethical in his work.  He likely did not cite his research, and committed plagiarism.   It is <span>the practice of taking someone else's work or ideas and passing them off as one's own.</span>

5 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following statements is true with regards to satellite Internet access?
    13·2 answers
  • Hardware consists of the physical devices associated with a computer system, where software is the set of instructions the hardw
    13·1 answer
  • Solver: Most of this class has already been written. Complete the solveRecurse() method using the backtracking. Also complete th
    10·1 answer
  • URGENT!!Motors and gears play an important role in the motion of robots. Discuss the different types of motors used in robotics.
    9·1 answer
  • 2) Show the decimal equivalent of each of the numbers if they are interpreted as (4 answers): 11001101 01101001 a. Unsigned bina
    15·2 answers
  • How do I write the yearly salary for something without copying it word for word? I'm doing a PowerPoint ( which you had to choos
    15·1 answer
  • One example of a <br> is the length of a car.
    7·1 answer
  • Write a program to calculate the farthest in each direction that Gracie was located throughout her travels. Add four print state
    10·1 answer
  • java Two smallest numbers Write a program that reads a list of integers, and outputs the two smallest integers in the list, in a
    6·1 answer
  • Why do we need to know the different Networking Devices?​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!