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
public class Sol {
public static void main(String[] args) {
if (args[2] = "M") {
o("Good Mr." + args[0] + ", you are " + (2021 - args[1]) + " years old.");
} else {
o("Good Mrs." + args[0] + ", you are " + (2021 - args[1]) + " years old.");
}
}
private static void o(String s) {
System.out.println(s);
}
}
Comments
Leave a comment