Answer:
Sample run :
Enter two numbers:
11.75 1.5
The minimum of 11.75 and 1.5 is 1.5
The maximum of 11.75 and 1.5 is 11.75
The sum of 11.75 and 1.5 is 13.25
The difference of 11.75 and 1.5, , rounded to the nearest whole integer, is 10
The product of 11.75 and 1.5 is 17.625
Explanation:
import java.util.Scanner;
public class Reader {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter two numbers: ");
double num1 = scan.nextDouble();
double num2 = scan.nextDouble();
System.out.println("The minimum of " + num1 + " and " + num2 + " is "
+ min(num1, num2));
System.out.println("The maximum of " + num1 + " and " + num2 + " is "
+ max(num1, num2));
System.out.println("The sum of " + num1 + " and " + num2 + " is "
+ sum(num1, num2));
System.out.println("The difference of " + num1 + " and " + num2
+ ", , rounded to the nearest whole integer, is "
+ difference(num1, num2));
System.out.println("The product of " + num1 + " and " + num2 + " is "
+ product(num1, num2));
scan.close();
}
private static double product(double n1, double n2) {
return n1 * n2;
}
private static double sum(double n1, double n2) {
return n1 + n2;
}
// using the absolute value method and the round method from the Math class
// to refine the results to the nearest whole positive integer.
private static int difference(double n1, double n2) {
double diff;
diff = n1 - n2;
diff = Math.abs(diff);
int intDiff = (int) Math.round(diff);
return intDiff;
}
private static double max(double n1, double n2) {
if (n1 > n2) {
return n1;
} else {
return n2;
}
}
static double min(double n1, double n2) {
if (n1 < n2) {
return n1;
} else {
return n2;
}
}
}