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


Expert's answer

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!

LATEST TUTORIALS
APPROVED BY CLIENTS