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