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

Question #244804

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-10-01T01:30:44-0400
package com.company;

import static java.lang.Math.abs;

public class Main {

    public static void main(String[] args) {
   // write your code here
        //declare the varibale to store name
        String name = args[0];
        //declare a variable to store the integer number in args[1]
        // by converting it to integer
        int my_integer_number = Integer.parseInt(args[1]);

        //declare a variable to store the double number in args[2]
        // by converting it to double
        double my_double_number = Double.parseDouble(args[2]);

        //declare a variable to store the difference
        double difference = my_integer_number - my_double_number;

        //Now print the greeting and the difference
        System.out.println("hello, "+name);
        System.out.println("The difference between "+(my_integer_number)
                +" and "+my_double_number+" is "+abs(difference));

    }
}

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

Olletu-vene
01.10.21, 09:47

Thank you This really helped me but you took a long time to send answers

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS