Courses‎ > ‎AP Computer Science‎ > ‎Konstantinovich‎ > ‎notes‎ > ‎

### 2017-10-06

posted Oct 6, 2017, 11:19 AM by Konstantinovich Samuel
 ```public class demo{ public static void main(String[]args){ Point P1 = new Point(1,1); Point P2 = new Point(2,2); System.out.println( distanceBetween(P1,P2)); System.out.println( Point.distanceBetween(P1,P2)); System.out.println( P1.distanceTo(P2)); } public static double distanceBetween(Point a, Point b){ return Math.sqrt( Math.pow(a.getX()-b.getX(),2) + Math.pow(a.getY()-b.getY(),2)); } }``````public class Point{ private double x,y; public Point(double X, double Y){ x=X; y=Y; } public double getX(){ return x; } public double getY(){ return y; } `````` public static double distanceBetween(Point a, Point b){ return Math.sqrt( Math.pow(a.getX()-b.getX(),2) + Math.pow(a.getY()-b.getY(),2)); //return Math.sqrt( Math.pow(a.x-b.x,2) + //Math.pow(a.y-b.y,2)); } public double distanceTo(Point other){ return Math.sqrt( Math.pow(getX()-other.getX(),2) + Math.pow(getY()-other.getY(),2)); //return return Math.sqrt( Math.pow(x - other.x,2)+ Math.pow(y - other.y,2)); } ```