Which of the following is the correct boolean expression to test for: int x being a value less than or equal to 500 or greater than 650, or int y not equal to 1000? a. ((x >= 500 && x < 650) && (y != 1000)) b. ((x <= 500 OR x > 650) AND !(y.equal(1000))) c. ((x <= 500 || x > 650) || (y != 1000)) d. ((x <= 500 || x > 650) && !(y == 1000))

Respuesta :

Answer:

c. ((x <= 500 || x > 650) || (y != 1000))

Step-by-step explanation:

  • x is an in type variable
  • y is an int type variable
  • Lets understand the Boolean expression:
  • According to the given condition, x has a value that should be less than or equal to 500. This shows that:                                                                    x < = 500
  • x has a value that should be greater than 650. This shows:                    x > 650
  • x being a value less than or equal to 500 OR greater than 650 means that either of the two conditions can hold because there is an OR between these two. OR in Boolean is represented as ||. So the expression becomes:

                                          x <= 500 || x > 650

  • y is not equal to 1000 shows: y!=100 Here NOT is represented by !
  • int x being a value less than or equal to 500 OR greater than 650, OR int y not equal to 1000 which makes the following Boolean expression:

                                  ((x <= 500 || x > 650) || (y != 1000))

  • The first OR is between the two expressions of x and the second OR is between x and y expressions.
  • Lets say the value of x entered is 400 and y is 900. The this expression evaluates to True.
  • Lets say the value of x entered is 501 and value of y is 1000. Then this Boolean expression evaluates to False.