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.Calendar;
import java.util.GregorianCalendar;
public class Lab01_Task04 {
public static void main(String[] args) {
System.out.println("Good " + (args[2].equals("M") ? "Mr " : "Ms ") + args[0]
+ ", you are " + (new GregorianCalendar().get(Calendar.YEAR) - Integer.parseInt(args[1])) + " year(s) old");
}
}
Comments
Leave a comment