Professional Documents
Culture Documents
6. What would be the output in Exercise 5 if the assignment were changed to the
following?
int extra = -32;
7. What would be the output in Exercise 5 if the assignment were changed to the following?
int extra = 0;
8. Write a multiway if-else statement that classifi es the value of an int variable n into one
of the following categories and writes out an appropriate message:
n < 0 or 0 n < 100 or n 100
Hint: Remember that the Boolean expressions are checked in order.
9. Suppose n1 and n2 are two int variables that have been given values. Write a Boolean
expression that returns true if the value of n1 is greater than or equal to the value of n2 ;
otherwise, it should return false .
10. Suppose n1 and n2 are two int variables that have been given values. Write an if-else
statement that outputs "n1" if n1 is greater than or equal to n2 , and that outputs "n2"
otherwise.
11. Determine the value, true or false , of each of the following Boolean expressions,
assuming that the value of the variable count is 0 and the value of the variable limit is
10. (Give your answer as one of the values true or false .)
a. (count == 0) && (limit < 20)
b. count == 0 && limit < 20
c . (limit > 20) || (count < 5)
d. !(count == 12)
e. (count == 1) && (x < y)
f. (count < 10) || (x < y)
g. !( ((count < 10) || (x < y)) && (count >= 0) )
h. ((limit/count) > 7) || (limit < 20)
i. (limit < 20) || ((limit/count) > 7)
j. ((limit/count) > 7) && (limit < 0)
k. (limit < 0) && ((limit/count) > 7)