// Exercise 5.19 Solution: DeMorgan.java // Program tests DeMorgan's laws. // Java extension packages import javax.swing.JOptionPane; public class DeMorgan { // method main begins execution of Java application public static void main( String args[] ) { String result = ""; int x = 6, y = 0; // part a if ( !( x < 5 ) && !( y >= 7 ) ) result += "\n!( x < 5 ) && !( y >= 7 )"; if ( !( ( x < 5 ) || ( y >= 7 ) ) ) result += "\n!( ( x < 5 ) || ( y >= 7 )"; int a = 8, b = 22, g = 88; // part b if ( !( a == b ) || !( g != 5 ) ) result += "\n!( a == b ) || !( g != 5 )"; if ( !( ( a == b ) && ( g != 5 ) ) ) result += "\n!( ( a == b ) && ( g != 5 ) )"; x = 8; y = 2; // part c if ( !( ( x <= 8 ) && ( y > 4 ) ) ) result += "\n!( ( x <= 8 ) && ( y > 4 ) )"; if ( !( x <= 8 ) || !( y > 4 ) ) result += "\n!( x <= 8 ) || !( y > 4 )"; int i = 0, j = 7; // part d if ( !( ( i > 4 ) || ( j <= 6 ) ) ) result += "\n!( ( i > 4 ) || ( j <= 6 ) )"; if ( !( i > 4 ) && !( j <= 6 ) ) result += "\n!( i > 4 ) && !( j <= 6 )"; JOptionPane.showMessageDialog( null, result, "DeMorgan's Laws", JOptionPane.INFORMATION_MESSAGE ); System.exit( 0 ); } } // end class DeMorgan