Ask Question
7 October, 01:38

Consider the following code segment, which is intended to set the Boolean variable inRange to true if the integer value num is greater than min value and less than max value. Otherwise inRange is set to false. Assume that inRange, num, min, and max have been properly declared and initialized. boolean isBigger; boolean isSmaller; boolean inRange; if (num min) { isBigger = true; } else { isBigger = false; } if (isBigger = = isSmaller) { inRange = true; } else { inRange = false; } Which of the following values of num, min, and max can be used to show that the code does NOT work as intended? a. num = 20, min = 30, max = 50

b. num = 30, min = 20, max = 40

c. num = 40, min = 10, max = 40

d. num = 50, min = 50, max = 50

e. num = 60, min = 40, max = 50

+1
Answers (1)
  1. 7 October, 01:51
    0
    Option d num = 50, min = 50, max = 50

    Explanation:

    Given the code segment:

    boolean isBigger; boolean isSmaller; boolean inRange; if (num min) { isBigger = true; } else { isBigger = false; } if (isBigger = = isSmaller) { inRange = true; } else { inRange = false; }

    If we have num = 50, min = 50, max = 50, the condition num < max will be evaluated to false and therefore isSmaller is set to false.

    The condition num > min will be evaluated to false as well and therefore isBigger is set to false.

    Since isSmaller and isBigger are both false and therefore isBigger = = isSmaller will be evaluated to true and set the inRange = true. This has violated the statement that if the integer value num is greater than min value and less than max value, then only set inRange to true. This is because num = 50 is neither greater than min nor less than max, it is supposedly not in range according to the original intention of the code design.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Consider the following code segment, which is intended to set the Boolean variable inRange to true if the integer value num is greater than ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers