Answer:
The program in Java is as follows:
import java.util.*;
import java.lang.Math;
public class Main{
public static int range(int low, int high){
return Math.abs(high - low)+1;
}
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int num1 , num2;
System.out.print("Enter two numbers: ");
num1 = scnr.nextInt();
num2 = scnr.nextInt();
System.out.print(range(num1,num2));
}
}
Explanation:
This defines the range method
public static int range(int low, int high){
This calculates and returns the range of the two numbers
return Math.abs(high - low)+1;
}
The main begins here
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
This declares 2 numbers as integer
int num1 , num2;
This prompt the user for two numbers
System.out.print("Enter two numbers: ");
The next two lines get input for the two numbers
num1 = scnr.nextInt();
num2 = scnr.nextInt();
This calls the range function and prints the returned value
System.out.print(range(num1,num2));
}