Write a java program that take input as a person name in the format of first, middle and last name and then print it in the form last, first and middle name, where in the middle name first character is capital letter

Write a java program that take input as a person name in the format of first, middle and last name and then print it in the form last, first and middle name, where in the middle name first character is capital letter.

import java.util.*;
class a2a4
{
String fname,mname,lname;
int len;
void accept()
{
System.out.println("Enter First Name :");
Scanner s=new Scanner(System.in);
fname=s.next();
System.out.println("Enter Middle Name :");
mname=s.next();
System.out.println("Enter Last Name :");
lname=s.next();
len=mname.length();
String f=mname.substring(0,1);
String l=mname.substring(1,len);
f=f.toUpperCase();
mname=f+l;
}
void display()
{
System.out.println("Last Name :"+lname);
System.out.println("First Name :"+fname);
System.out.println("Middle Name :"+mname);
}
public static void main(String a[])
{
a2a4 p=new a2a4();
p.accept();
p.display();
}
}

Output:

Enter First Name :
rohit
Enter Middle Name :

rajesh
Enter Last Name :
bairwa
Last Name :bairwa
First Name :rohit
Middle Name :Rajesh

Post a Comment

0 Comments