Answer:
Following is the program in Java language:
import java.util.*;//import package
public class Main // main class
{
public static void main(String[] args) // main method
{
String firstname,lastname; // Declare the two String variables
Scanner ob=new Scanner(System.in); // create a object of scanner //class
System.out.println("Enter the first name:"); // Prompt the user for // enter the first name
firstname=ob.nextLine();// Read in the first name by user
System.out.println("Enter the last name:"); // Prompt the user for last //name
lastname=ob.nextLine();// Read in the last name by user
System.out.println("Hello " + firstname +' ' +lastname); // print the //firstname,lastname
}
}
Output:
Enter the first name:
San
Enter the last name:
ert
Hello San ert
Explanation:
Following are the description of program
- Declared two variable of string type i.e "firstname" and "lastname".
- Create a instance or object of scanner class .i.e "ob".
- Prompt the user to enter the first name in the "firstname" variable
- Read in the first name by the user by using the method nextLine() in the first name variable
- Prompt the user to enter the last name.
- Read in the last name by the user by using the method nextLine() in the lastname variable.
- Finally, print the first name and last name.