Answer to Question #244802 in Java | JSP | JSF for Olletu-vene

Question #244802

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


1
Expert's answer
2021-09-30T06:42:24-0400
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);
  }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS