• 2. Get all the information from the user using methods.
• A. Name, email id, phone number, age. → Conditions are to be used here
ANSWER:
Here I used Constructor and Conditions for user details. If conditions will true then that statement print perticular values.
public class Main
{
String Name;
String email;
int phno;
int age;
Main(String Name,String email,int phno,int age)
{
this.Name=Name;
this.email=email;
this.phno=phno;
this.age=age;
}
void getInfo()
{
if(Name.equals("Pulkit"))
{
System.out.println("Name:"+Name);
}
if(email.equals("hellopulkit"))
{
System.out.println("Email:"+email);
}
if(phno==1234567890)
{
System.out.println("phno:"+phno);
}
if(age==19)
{
System.out.println("Age:"+age);
}
}
public static void main(String[] args) {
Main cl=new
Main("Pulkit","hellopulkit",1234567890,19);
cl.getInfo();
}
}
Get Answers For Free
Most questions answered within 1 hours.