IfStatement.java



/*IfStatement.java

< applet
code=IfStatement
width=200
height=200 >
< /applet >

This example demonstrates If Statements.  */

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

public class IfStatement extends Applet
 {

   TextArea Result=new TextArea(5,20);
   Button ShowIt=new Button("Determine the output.");
	
	public void init()
    {

      add(ShowIt);
      add(Result);
    }

public boolean action (Event thisEvent, Object thisObject)
{

   int a = 10;
   int b = 20;
   int c = -10;  
   int d = 1;
   int k = 2;
   k *= 4 + d;
   d += a * (-b + c) / 100;
   if (a < b ) Result.appendText("***\n");
   if (c > b) Result.appendText("###\n");
   if (c == 5) Result.appendText("!!!\n");
   else Result.appendText("mmm\n");
   Result.appendText("d = "+d+"\n");
   if (d != -1)
     {
       Result.appendText("not equal k="+k+" \n");
       k -= d + 4;
       Result.appendText("k= "+k+"");
     }
   else
     {
       Result.appendText("equal k=" +k+ "\n");
       k -= d * 4;
       Result.appendText("k=" +k+ "\n");
     }

 
   return true;
}

}

Output for IfStatement.java