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
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));
}
}
Comments
Thank you This really helped me but you took a long time to send answers
Leave a comment