Example 5.4
//pag 71 or 51 http://www.greenteapress.com/thinkapjava/thinkapjava.pdf
 
public class example_5_4
{
 
    public static double area(double radius) {
        return Math.PI*radius*radius;
    }
 
    public static double distance(double x1, double y1, double x2, double y2) {
        double dx = x1 - x2;
        double dy = y1 - y2;
        double result = Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2));
        return result;
    }
 
    public static double area(double xc, double yc, double xp, double yp) {
        return area(distance(xc, yc, xp, yp));
    }
 
    public static void main(String [] args) {
        double area = area(1.0, 2.0, 4.0, 6.0);
        System.out.println(area + " units");
    }
}

voltar

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.