Area of Rectangle

In this example the area of a rectangle is calculated by the method areaRectangle. The result is then passed back to the paint method for printing.

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

public class areaExample extends Applet {

public void paint(Graphics g) {

int area;
area=areaRectangle(30, 40);
g.drawString("Area of rectangle is "+area, 50, 50);

}
private int areaRectangle(int side1, int side2) {

int areaCalc
areaCalc= side1 * side2;
return areaCalc;

}

}

This is the output:

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License