public class ComplexBooleanExpressions
2: /**
3: * NOTE: The exercise asks for boolean expressions, and so the answers
4: * should just be the bits inside the (parentheses). But that won't
5: * compile in Java, so I added "if" at the beginning and ";" at the end.
6: * Java accepts this, even tho' the result is not actually a command....
7: *
8: * @author Mark Young (A00000000)
9: */
10: public class ComplexBooleanExpressions {
12: public static void main(String[] args) {
13: // create some variables
14: double x, y, z;
15: int m, n;
17: // initialize them
18: x = 4.0;
19: y = 7.3;
20: z = 9.9;
21: m = 20;
22: n = 35;
24: // x is greater than 0 and y is less than 5
25: if (x > 0 && y < 5) {
26: System.out.println(x + " > 0 && " + y + " < 5 is true");
27: } else {
28: System.out.println(x + " > 0 && " + y + " < 5 is false");
29: }
31: // x is greater than zero or y is equal to z
32: if (x > 0 || y == z) {
33: System.out.println(x + " > 0 || " + y + " == " + z + " is true");
34: } else {
35: System.out.println(x + " > 0 || " + y + " == " + z + " is false");
36: }
38: // it's not the case that x is greater than the product of y and z
39: // NOTE: translate directly to Java
40: if (!(x > y * z)) {
41: System.out.println("!(" + x + " > " + y + " * " + z + ") is true");
42: } else {
43: System.out.println("!(" + x + " > " + y + " * " + z + ") is false");
44: }
46: // y is greater than x and less than z
47: if (y > x && y < z) {
48: System.out.println(y + " > " + x + " && " + y + " < " + z + " is true");
49: } else {
50: System.out.println(y + " > " + x + " && " + y + " < " + z + " is false");
51: }
53: // x is equal to y but not to z
54: if (x == y && x != z) {
55: System.out.println(x + " == " + y + " && " + x + " != " + z + " is true");
56: } else {
57: System.out.println(x + " == " + y + " && " + x + " != " + z + " is false");
58: }
60: // m or n is greater than 0
61: if (m > 0 || n > 0) {
62: System.out.println(m + " > 0 || " + n + " > 0 is true");
63: } else {
64: System.out.println(m + " > 0 || " + n + " > 0 is false");
65: }
67: }
69: }