Logical1.java



/*Logical1.java
This applet will demonstrate the AND, OR, and NOT Logical Operators.

< applet
code=Logical1
width=250
height=250 >
< /applet >

*/

import java.applet.*;
import java.awt.*;

public class Logical1 extends Applet
{
  Label Line1 = new Label("This applet will demonstrate Logical Operators");
  Button ShowIt=new Button("Go");
  TextArea Result=new TextArea(10,35);
  public void init()
  {
  add(Line1);
  add(ShowIt);
  add(Result);
  }


  public boolean action (Event thisEvent, Object thisObject)
  {
    
	  boolean a = true;
	  boolean b = false;
	  boolean c = a | b; // OR operator
	  boolean d = a & b; // AND operator
	  boolean e = !a; //NOT operator
	  boolean f = (!a & b) | (a & !b); 
	  boolean g = !((a & b) & (a & !b));
	  
	  Result.appendText("a = "+a+" \n");
	  Result.appendText("b = "+b+" \n");
	  Result.appendText("a | b = "+c+" \n");
	  Result.appendText("a & b = "+d+" \n");
	  Result.appendText("( !a & b ) | ( a & !b ) = "+f+" \n");
	  Result.appendText("!a = "+e+" \n");
	  Result.appendText("! ( ( !a & b ) & ( a & !b ) ) = "+f+" \n");

	  return true;

  }
}

Output for Logical1.java