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
package com.task;
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
String name = args[0];
Integer birthYear = Integer.valueOf(args[1]);
String gender = args[2];
String title = "M".equals(gender) ? "Mr" : "Ms";
Integer currentYear = Calendar.getInstance().get(Calendar.YEAR);
Integer age = currentYear-birthYear;
System.out.println("Good " + title + " " + name + ", you are " + age + " years old");
}
}
Comments
Leave a comment