Write a program in Java to accept a name containing three words and display the. surname first followed by the first and middle names
Answers
If you have any doubt pls leave a comment.
Program:
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
String fullName="";
String[] str;
Scanner scanner=new Scanner(System.in);
System.out.println("Enter the full name:");
fullName=scanner.nextLine();
System.out.println("The names after split is:");
str = fullName.split(" ");
System.out.println("Surname : "+str[0]);
System.out.println("First name : "+str[1]);
System.out.println("Middle name : "+str[2]);
}
}
Input:
Enter the full name:
Ivaturi Puja Ankitha
Output:
The names after split is:
Surname : Ivaturi
First name : Puja
Middle name : Ankitha
Learn more:
1. Write a program to check whether it is a Lead number or not in java
https://brainly.in/question/15644815
2. Write a java program to input name and mobile numbers of all employees of any office. Using "Linear Search", search array of phone numbers for a given "mobile number" and print name of employee if found, otherwise print a suitable message.
brainly.in/question/18217872