Java program that computes the sum, difference, product, average, distance, maximum and minimum of two numbers
###### Posted by Samath
Last Updated: February 08, 2021

Write a program that prompts the user for two integers and then prints
• The sum
• The difference
• The product
• The average
• The distance (absolute value of the difference)
• The maximum (the larger of the two)
• The minimum (the smaller of the two)
Hint: The max and min functions are declared in the Math class.

Example:

Please enter the 1st number: 5
Please enter the 2nd number: 10
Sum: 15.00
Difference: -5.00
Product: 50.00
Average: 7.50
Distance: 5.00
Maximum: 10.00
Minimum: 5.00

```import java.util.Scanner;

public class Main
{
public static void main(String[] args) {

Scanner input = new Scanner(System.in);

double num1;
double num2;
double sum;
double difference;
double product;
double average;
double distance;
double maximum;
double minimum;

System.out.print("Please enter the 1st number: ");
num1 = input.nextDouble();

System.out.print("Please enter the 2nd number: ");
num2 = input.nextDouble();

input.close();

sum = num1 + num2;
difference = num1 - num2;
product = num1 * num2;
average = (num1 + num2) / 2;
distance = Math.abs(difference);
maximum = Math.max(num1, num2);
minimum = Math.min(num1, num2);

System.out.printf("\nSum: %.2f\n", sum);

System.out.printf("Difference: %.2f\n",difference);

System.out.printf("Product: %.2f\n", product);

System.out.printf("Average: %.2f\n", average);

System.out.printf("Distance: %.2f\n", distance);

System.out.printf("Maximum: %.2f\n", maximum);

System.out.printf("Minimum: %.2f", minimum);
}
}
```
###### C program that generates a random positive float number in a fixed interval with a maximum distance between endpoints of 100
Samath | Jan 01, 2017
###### C program that prompts the user for a positive integer and then computes the sum of all the digits of the number
Samath | May 04, 2016
###### C program to read three numbers and find maximum of the three numbers
Samath | Jan 02, 2017
###### C++ program that prompts the user to input five decimal numbers, prints the five decimal numbers, converts each decimal number to the nearest integer, adds the five integers and prints the sum and average of the five integers.
Samath | Apr 06, 2022
###### C++ program that calculates the average of three test scores
Samath | Nov 15, 2014
###### Java program that prints the product of the first ten positive integers
Samath | Jan 08, 2021
###### Sum of two values in C
Samath | Nov 09, 2014
###### C Program to find sum of two numbers
Samath | Jan 02, 2017
###### C++ Calculate the sum from 1 to 100
Samath | Jan 05, 2017
###### Java program that asks the user for a year and computes whether that year is a leap year
Samath | May 08, 2021
###### Java program that computes income tax
Samath | May 08, 2021
###### C++ program that computes and displays the charges for a patientâ€™s hospital stay
Samath | Jan 06, 2021
###### Java program that compute the average test score for a student and assign the appropriate letter grade
Samath | Jan 17, 2024
###### Write a C++ program that find the sum of all even numbers between 1 and 30 excluding 6, 8, 24 and 28
Samath | Nov 02, 2014