Program:-
import java.util.Scanner;
class Name
{
private String First_name;
private String Middle_name;
private String Last_name;
public void setName(String First,String Middle,String Last)
{
First_name = First;
Middle_name = Middle;
Last_name = Last;
}
public String getFirst()
{
return First_name;
}
public String getMiddle()
{
return Middle_name;
}
public String getLast()
{
return Last_name;
}
public void FirstMiddleLast()
{
System.out.println(First_name+" "+Middle_name+" "+Last_name);
}
public void LastFirstMiddle()
{
System.out.println(Last_name+" "+First_name+" "+Middle_name);
}
}
class NameTest
{
public static void main(String[] args)
{
Name a = new Name();
String b,c,d;
System.out.print("Enter First name:");
Scanner sc= new Scanner(System.in);
b=sc.nextLine();
System.out.print("Enter Middle name:");
c=sc.nextLine();
System.out.print("Enter Last name:");
d=sc.nextLine();
a.setName(b,c,d);
System.out.println("Full name is:");
a.FirstMiddleLast();
a.LastFirstMiddle();
}
}
Output:-
import java.util.Scanner;
class Name
{
private String First_name;
private String Middle_name;
private String Last_name;
public void setName(String First,String Middle,String Last)
{
First_name = First;
Middle_name = Middle;
Last_name = Last;
}
public String getFirst()
{
return First_name;
}
public String getMiddle()
{
return Middle_name;
}
public String getLast()
{
return Last_name;
}
public void FirstMiddleLast()
{
System.out.println(First_name+" "+Middle_name+" "+Last_name);
}
public void LastFirstMiddle()
{
System.out.println(Last_name+" "+First_name+" "+Middle_name);
}
}
class NameTest
{
public static void main(String[] args)
{
Name a = new Name();
String b,c,d;
System.out.print("Enter First name:");
Scanner sc= new Scanner(System.in);
b=sc.nextLine();
System.out.print("Enter Middle name:");
c=sc.nextLine();
System.out.print("Enter Last name:");
d=sc.nextLine();
a.setName(b,c,d);
System.out.println("Full name is:");
a.FirstMiddleLast();
a.LastFirstMiddle();
}
}
Output:-
No comments:
Post a Comment