Question

In: Computer Science

(10 pts) Write a function called isInBetween that takes 3 ints, say n, low and high,...

(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.

Solutions

Expert Solution

/* 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********/


Related Solutions

C Language - Programming Write a function that takes an array of ints, and the size...
C Language - Programming Write a function that takes an array of ints, and the size of the array – another int. It also returns a double. Call this one ‘average.’ Return a double that is the average of the values in the array. Demonstrate that it works by finding the average of an array with these values {78, 90, 56, 99, 88, 68, 92} Write a function that takes one double parameter, and returns a char. The parameter represents...
In C++ Write a function which takes two parameters: an array of ints and an int...
In C++ Write a function which takes two parameters: an array of ints and an int size of the array and prints every element greater than 5 to the screen. As an example, if the array has the following 10 elements: 2 5 8 9 7 1 0 2 6 3, your function should print out 8 9 7 6. You may assume that the parameters passed to the function are valid. Your function must have the following signature: void...
Write a function called alternate that takes two positive integers, n and m, as input arguments...
Write a function called alternate that takes two positive integers, n and m, as input arguments (the function does not have to check the format of the input) and returns one matrix as an output argument. Each element of the n-by-m output matrix for which the sum of its indices is even is 1. All other elements are zero. For example, here is an example run: >> alternate(4,5) ans = 1 0 1 0 1 0 1 0 1 0...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes one doyble argument called "num". The function will declare, ask, and get another double from the user. Compare the double entered by the user to "num" and return a 0 if they are the same, a -1 num is less than the double entered by the user and 1 if it is greater.
PYTHON 3: Write a recursive function that takes a non-negative integer n as input and returns...
PYTHON 3: Write a recursive function that takes a non-negative integer n as input and returns the number of 1's in the binary representation of n. Use the fact that this is equal to the number of 1's in the representation of n//2 (integer division) plus 1 if n is odd. >>>numOnes(0) 0 >>>numOnes(1) 1 >>>numOnes(14) 3
Write a function called swapElements to swap two elements in a character array. This function takes...
Write a function called swapElements to swap two elements in a character array. This function takes two parameters, a character array and input file. The function should read two numbers from a file and it swap the elements stored in the indices read. please code in c++
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or...
A. Write a function in MATLAB called findTranspose that takes in as input any matrix or any vector and simply returns back the transpose of that input. You can always verify your answer by using the inbuilt transpose function in MATLAB, however, you cannot use the transpose function directly when writing your code. Here is the starter code that we are providing to help you get started %x is the input vector or matrix. You can find the %size that...
C++ Write a function called linearSearch that takes an array as a parameter and search for...
C++ Write a function called linearSearch that takes an array as a parameter and search for a specific value inside this parameter. The function returns the frequency of a specific value in the array. In the main function: 1. Define an array called salaries of length 5. 2. Initialize the array by asking the user to input the values of its elements. 3. Define a variable called key and ask the user to enter a value for this variable. 4....
JavaScript Write a function called "first" that takes in two arguments - the first is an...
JavaScript Write a function called "first" that takes in two arguments - the first is an argument called arr that is an array of numbers, the second is an optional number argument called num(hint: you'll need a default value - look back at the slides). If "num" was not passed in (since it's optional), the "first" function will return an array containing the first item of the array. If a value for "num" was given, the "first" function will return...
Write a recursive function in python called make_palindrome that takes a sequence as a parameter and...
Write a recursive function in python called make_palindrome that takes a sequence as a parameter and returns a new sequence that is twice the length of the parameter sequence but that contains the contents of the original in palindrome form. For example, if the sequence "super" is passed into the function, the function will return "superrepus".
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT