Create a program that when run with a name, an integer and a double as CMD arguments, it prints out a greeting using the name and also print the difference of the two given numbers:
Sample run 1:
java Lab01_task85 John 25 18.65
Output: Good day John.
The difference between 25 and 18.650 = 6.35
public class Console {
public static void main(String[] args) throw RuntimeException {
System.out.printf("Good day %s.", args[0]);
System.out.printf("The difference between %s and %s = %.2f", args[1], args[2], Math.abs(dif(args[1], args[2])));
}
private static double dif(String a, String b) {
return Double.parseDouble(a) - Double.parseDouble(b);
}
}
Comments
Leave a comment