Answer:
import java.util.Scanner;
public class num6 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter first number");
int a = in.nextInt();
System.out.println("Enter second number");
int b = in.nextInt();
//Calling the methods inside the output statement
System.out.println("Min is "+min(a,b));
System.out.println("Max is "+ max(a,b));
System.out.println("Sum is "+sum(a,b));
System.out.println("Product is "+product(a,b));
System.out.println("Absolute difference is "+difference(a,b));
}
//Min Method
static int min(int a, int b){
if (a<b){
return a;
}
else {
return b;
}
}
//Max Method
static int max(int a, int b){
if (a>b){
return a;
}
else {
return b;
}
}
//Sum Method
static int sum(int a, int b){
return a+b;
}
//Diference Method
static int difference(int a, int b){
int diff = Math.abs(a-b);
return diff;
}
//Product Method
static int product(int a, int b){
int prod = a*b;
return prod;
}
}
Explanation:
- Using Java programming language
- Use the scanner class to prompt and receive two values from the user (integers a and b)
- Create the four methods as required (Please see the comments in the code)
- In the difference method use Math.abs() to get the absolute value of the subtraction ensuring that you get a positive number returned