Write a Java program to accept first name, middle name and surname in three different strings and then concatenate the three strings to make full name.
import java.util.Scanner;
public class FullNameString {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter first name :: ");
String firstName = input.nextLine();
System.out.print("Enter middle name :: ");
String middleName = input.nextLine();
System.out.print("Enter surname :: ");
String lastName = input.nextLine();
// Here StringBuffer is used to combine 3 strings into single
StringBuffer fullName = new StringBuffer();
fullName.append(firstName);
fullName.append(" "); // For space between names
fullName.append(middleName);
fullName.append(" "); // For space between names
fullName.append(lastName);
System.out.println("Hello, " + fullName);
}
}
Enter first name :: Rahul
Enter middle name :: S.
Enter surname :: Tamkhane
Hello, Rahul S. Tamkhane