#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Help with reading basic code


    Hey everybody, I would love some help as to what the output of this program is and how you get there.

    public static double distance (Point p1, Point p2) {
    int dx = p1.x - p2.x;
    int dy = p1.y - p2.y;
    return Math.sqrt (dx*dx + dy*dy);
    }
    public static Point findCenter (Rectangle box) {
    int x = box.x + box.width/2;
    int y = box.y + box.height/2;
    return new Point (x, y);
    }
    public static void main (String[] args) {
    Point blank = new Point (5, 8);
    Rectangle rect = new Rectangle (0, 2, 4, 4);
    Point center = findCenter (rect);
    double dist = distance (center, blank);
    System.out.println (dist);
    }

    Thanks!
  2. #2
  3. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,418
    Rep Power
    1713
    When you compiled it and ran it what output did it give you? If you added some simple System.out.println() statements then you could probably see what it is doing.

IMN logo majestic logo threadwatch logo seochat tools logo