- Open DrJava or clear the Interactions Pane by right-clicking and selecting Reset Interactions.
- Declare and assign values for the variables A and B.
> boolean A = true; > boolean B = true;
- Test De Morgan’s laws by typing in the following.
> !(A && B) false > !A || !B false > !(A && B) == !A || !B true >
- Now type the following.
> !(A || B) == !A && !B false > !(A || B) false > !A && !B false > !(A || B) == !A && !B false
- Note that the final statement return false, which seems to be in error.
- Modify the final statement to appear as follows, note that although incomplete, the result is now true.
> !(A || B) == !A true
- Modify the statement to appear as follows, the result is true, as we forced the correct order of operation.
> !(A || B) == (!A && !B) true
- Reset the Interactions pane and declare X and Y as integers, assign six to x and 3 to y.
> int x = 6; > int y =3;
- Type the following statements and note the results.
> !(x < 5 && y == 3) true > x >= 5 || y != 3 true > !(x >=1 || y != 7) false > x < 1 && y == 7 false