0% found this document useful (0 votes)
95 views2 pages

Java Boolean Logic Exercises

Uploaded by

4btkkdmzxg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views2 pages

Java Boolean Logic Exercises

Uploaded by

4btkkdmzxg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

In problems 6-10, assume the following and determine the output:

int z = 23, x = -109;


double c = 2345.19, v = 157.03;
boolean a = false, s = true;

6. boolean gus = (x > 0) && (c = = v);


System.out.println (!gus);
false
7. System.out.println (a || s);
true
8. System.out.println (((-1 * x) > 0) && !a);
true
9. boolean r = z = =x;
System.out.println(r || false);
false
10. System.out.println (z!=x);
true

11. Fill in the following charts.

a b (!a && b) a b (a || !b)

false false false false false true


false true true false true false
true false false true false true
true true false true true true

12. Assume b, p, and q are booleans. Write code that will assign to b the result of ANDing
p and q.
boolean b = p && q;

13. Assign to the boolean variable w the result of OR-ing the following two things:

A test to see if x is positive:

A test to see if y equals z:


boolean w = x > 0 || y == z;

14. What are the two possible values of a boolean variable?


true, false
15. Write a test that will return a true if a is not equal to b. Assume a and b are integers.
Store the result in boolean kDog.
kDog = a != b;

16. Write the answer to #15 another way.


kDog = ! (a == b);

17. What is the Java operator for boolean AND-ing?


&&
18. What is the Java operator for boolean OR-ing?
||
In questions 19-23, what is the output?

19. System.out.println ((true && false) || ((true && true) ||


false));
true

20. System.out.println (true && true || false);


true

21. System.out.println (true || true && false);


false

22. System.out.println (false || true && false);


false

23. System.out.println (false && true || false);


false

You might also like