[NHS Homepage] [Academic Cooperative Grant Page] [Computer Programming 2] [Syllabus]


IncreDecreOper.java


/*IncreDecreOper.java 
This applet will demonstrate Increment and Decrement Operators.

< applet
code=CompoundOp
width=200
height=200 >
< /applet >
*/

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



public class IncreDecreOper extends Applet
 {

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

public boolean action (Event thisEvent, Object thisObject)
{

   int j = 3;
   int c = 10;
   int k = 2;
   int m = 5;
   int a;
   int b;
   int d;
   int f;
   a = j++ + k;
   b = ++j + k;
   d = c-- + k;
   f = --c + k;
   m++;
   Result.appendText("a="+a+"\n");
   Result.appendText("b="+b+"\n");
   Result.appendText("\nd= "+d+" **** f= "+f+" ");
   Result.appendText("\nm= "+m+" **** "+(m++ + ++d + --a + b--)+" ");
   Result.appendText("\nm= "+m+" **** d= "+d+" ");
   Result.appendText("\na= "+a+" **** b= "+b+" ");
   return true;
}

}


Output for IncreDecreOper.java