ModIntDiv.java


/*ModIntDiv.java
This applet will demonstrate float, integer & Mod Division.

< applet
code=ModIntDiv
width=200
height=225 %gt
< /applet %gt
*/
import java.awt.*;
import java.applet.*;

public class ModIntDiv extends Applet
{
  Button Calculate = new Button("Calculate");
  TextArea result = new TextArea(11,25);

  public void init()
  {
    add (Calculate);
	add(result);

   }

public boolean action (Event thisEvent, Object thisObject)
{
  int num1 = 25 / 4;
  int num2 = 25 % 4;
  double num3 = 25.0 / 4;
  
  int num4 = -23 / 3;
  int num5 = -23 % 3;
  double num6 = -23 / 3.0;
  
  int num7 = 1 / -5;
  int num8 = 1 % -5;
  double num9 = 1.0 / -5.0;
    
  result.appendText("25 / 4 = "+num1+"\n" + 
	            "25 % 4 = "+num2+"\n" +
		    "25.0 / 4 = "+num3+"\n\n" +

                    "-23 / 3 = "+num4+"\n" +
		    "-23 % 3 = "+num5+"\n" + 
         	    "-23 / 3.0 = "+num6+"\n\n" + 

                    "1 / -5 = "+num7+"\n" +
                    "1 % -5 = "+num8+"\n" +
                    "1.0 / -5.0 = "+num9+"\n");

  return true;
}
}


Output for ModIntDiv.java