2007年11月8日 星期四

第四題

import java.awt.geom.Point2D;
class ComputeDistance {
public static void main (String args[]) {double sum;Point2D.Double p1 = new Point2D.Double(611798.9819, 13533031.19);Point2D.Double p2 = new Point2D.Double(610894.7525, 13532383.89);Point2D.Double p3 = new Point2D.Double(610238.106, 13534984.8);Point2D.Double p4 = new Point2D.Double(609339.6426, 13533147.72);Point2D.Double p5 = new Point2D.Double(608504.4173, 13535447.88);
System.out.println("P1到P2的距離: " + p1.distance(p2));System.out.println("P2到P3的距離: " + p2.distance(p3));System.out.println("P3到P4的距離: " + p3.distance(p4));System.out.println("P4到P5的距離: " + p4.distance(p5));
sum = p1.distance(p2) + p2.distance(p3) + p3.distance(p4) + p4.distance(p5);System.out.println("總距離為: " + sum);
}
}

沒有留言: