IDNLearn.com makes it easy to get reliable answers from experts and enthusiasts alike. Get the information you need quickly and accurately with our reliable and thorough Q&A platform.
Sagot :
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));
}
Thank you for joining our conversation. Don't hesitate to return anytime to find answers to your questions. Let's continue sharing knowledge and experiences! IDNLearn.com is your source for precise answers. Thank you for visiting, and we look forward to helping you again soon.