Pre Lab #9: Exercise Sheet Print out this exercise sheet, complete it and turn it in to your lab instructor before your lab session on Wednesday/Thursday ends. 1) Write a Boolean expression for each of the following statements. Assume that x, y and z are int variables and have been declared. a) 2 times x is greater than 3 times y but less than z. ___________________________________________________________________________ b) x is even. ___________________________________________________________________________ c) y is odd. ___________________________________________________________________________ d) x is odd and y is even. ___________________________________________________________________________ e) One of x and y is even and the other is odd. ___________________________________________________________________________ Hints: i) An integer is odd when the remainder of dividing the integer by 2 is 1. On the other hand, an integer is even when the remainder of dividing the integer by 2 is 0. ii) Use the remainder operator (%). 2) Write a Boolean expression for each of the following sentences. Assume that year is an int variable already declared that stores an integer greater than or equal to zero. a) year is a century. ___________________________________________________________________________ b) year is a century and is divisible by 400. ___________________________________________________________________________c) year is not a century and divisible by 4. ___________________________________________________________________________ d) year is not a century and is divisible by 4 or a century divisible by 400. ___________________________________________________________________________ Hints: • A century is 100 years. • An integer a is divisible by another integer b when the remainder of a divided by b is zero. • Use the remainder (%) operator to compute the remainder. 3) For each of the Boolean expressions below, circle its truth-value. int a=5, b=3, c=9; boolean e=true, f=false; a) c % b > a - b true false b) e && f || true true false c) a > c && b + 6 < c || b !=c true false d) (a > c || b + 8 >= c) && b !=c || !e true false e) ! (a == b) || e && b < c && a<=c || !f true false f) b !=c && (a > c || b + 8 >= c) || !f true
View Full Document