In: Computer Science
(10 pts) Write a function called isInBetween that takes 3 ints, say n, low and high, and returns a boolean; the function returns true if the first parameter (n) is between the second and third parameters (low and high, INCLUSIVE), and false otherwise. Can safely assume that low is lower than high.
/* I have written this code in java as you have not
mentioned
any specific language in the question,Please do ask in case of any
doubt,Thanks */
import java.util.*;
public class HelloWorld{
public static void main(String []args){
Scanner input=new Scanner(System.in); //object for taking
input
System.out.println("Enter n: ");
int n=input.nextInt(); //first parameter
System.out.println("Enter low: ");
int low=input.nextInt(); //second parameter
System.out.println("Enter hih: ");
int high=input.nextInt(); //third parameter
//calling isInBetween(n,low,high) and printing the returned
value
System.out.println("Result: "+isInBetween(n,low,high));
}
/* method isInBetween(n,low,high) */
public static boolean isInBetween(int n,int low,int high){
/* if 1 parameter is in between low and high return true */
if(low<=n && n<=high)
return true;
else /* else return false */
return false;
}
}
/*******OUTPUT********
sh-4.3$ javac HelloWorld.java
sh-4.3$ java -Xmx128M -Xms16M HelloWorld
Enter n:
2
Enter low:
1
Enter hih:
3
Result: true
**********OUTPUT********/