Create a program that gets values as CMD args as follows, a person's name, year of birth and gender. The program then prints a message as follows:[HINT: if the person is male then the program uses Mr otherwise use Ms]
Sample 01:
Java Lab01_Task04 John 1999 M
Output
Good Mr John, you are 21 years old
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
String name;
int year_of_birth;
String gender;
System.out.print("Enter name: ");
name=in.next();
System.out.print("Enter year of birth: ");
year_of_birth=in.nextInt();
System.out.print("Enter gender: ");
gender=in.next();
if (gender.equals("male")){
System.out.println("Good Mr "+name+", you are "+(2021- year_of_birth)+" years old");
}
else if(gender.equals("female")){
System.out.println("Good Ms "+name+", you are "+(2021- year_of_birth)+" years old");
}
}
}
Comments
Leave a comment