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.io.*;

import java.util.*;

class person

{

String fname,mname,lname;

int len;

Scanner sc=new Scanner(System.in);

void accept()

{

System.out.println("Enter the first name");

fname=sc.next();

System.out.println("Enter the Middle name");

 mname=sc.next();

System.out.println("Enter the Last name");

 lname=sc.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("First name is:: "+fname);

System.out.println("Middle name is:: "+mname);

System.out.println("Last name is:: "+lname);

}

public static void main(String args[])

{

person p=new person();

p.accept();

p.display();

}

}

Post a Comment

0 Comments