Range Problems Using Conditional Testing


Problem: Range Test 1

Write a JAVA program named isInRange1 that prompts the user to enter two integers, the first to identify the lowest value of a range of integers, the second to identify the upper value of a given range of integers.

The program will then prompt the user to enter an integer that is to be tested to see if it falls within the range of the low value and high value, inclusive.

For the purposes of this program you may assume that the user will input the low value first, and the high value second, therefore no data validation is required.

As output, the program will display a message “value is in range” if the search value is between or equal to one of the range values. Otherwise, the program will display a message “value is not in range”.

Sample Program Data
Program Run  First Input Value  Second Input Value  Test Value  Output Message
13127 7 is in range
29366 is not in range
Initial Questions
Algorithm
Solution
Video

Problem: Range Test 2

Write a JAVA program named isInRange2 that prompts the user to enter two integers that represent the outer bounds of a range of values.

The program will then prompt the user to enter an integer that is to be tested to see if it falls within the range of the first two integers, inclusive.

Note: for purposes of this program, the user is not obligated to enter the lowest value first.

As output, the program will display a message “value is in range” if the search value is between or equal to one of the range values. Otherwise, the program will display a message “value is not in range”.

Sample Program Data
Program Run  First Input Value  Second Input Value  Test Value  Output Message
13127 7 is in range
212366 is in range
361233 is not in range
Initial Questions
Algorithm
Solution
Video

Problem: Find Minimum Value

Write a JAVA program named MinVal that prompts the user to input 3 integer values. As output the program will display the smallest of the three.

Sample input/output

Input values:   7  9  2
Output:   2

Initial Questions
Algorithm
Solution
Video

Problem: Find the Maximum Value

Write a JAVA program named MaxVal that prompts the user to input 3 integer values. As output the program will display the largest of the three.

Input values:   7  9  2
Output:   9

Initial Questions
Algorithm
Solution
Video