2007年11月9日 星期五

第五題

import java.io.*;
import java.awt.geom.Point2D;
public class KeyIn {public static void main(String[] args) throws IOException { BufferedReader keyin;
keyin = new BufferedReader(new InputStreamReader(System.in));
double p11, p12, p21, p22, p31, p32;
System.out.println("keyin p11: ");
String n1 = keyin.readLine();
p11 = Double.parseDouble(n1);
System.out.println("keyin p12: ");
String e1 = keyin.readLine();
p12 = Double.parseDouble(e1);
System.out.println("keyin p21: ");
String n2 = keyin.readLine();
p21 = Double.parseDouble(n2);
System.out.println("keyin p22: ");
String e2 = keyin.readLine();
p22 = Double.parseDouble(e2);
System.out.println("keyin p31: ");
String n3 = keyin.readLine();
p31 = Double.parseDouble(n3);
System.out.println("keyin p32: ");
String e3 = keyin.readLine();
p32 = Double.parseDouble(e3);
Point2D.Double p1 = new Point2D.Double(p11, p12);
Point2D.Double p2 = new Point2D.Double(p21, p22);
Point2D.Double p3 = new Point2D.Double(p31, p32);
System.out.println("P1到P2的距離: " + p1.distance(p2));
System.out.println("P2到P3的距離: " + p2.distance(p3));
}
}

第四題

import java.awt.geom.Point2D;
class Diascomput {
public static void main (String args[]) {
Point2D.Double p1=new Point2D.Double(2777311.707,379074.9058);
Point2D.Double p2=new Point2D.Double(2777577.196,379794.8637);
Point2D.Double p3=new Point2D.Double(2779178.763,378124.9738);
Point2D.Double p4=new Point2D.Double(2780148.806,372998.4286);
Point2D.Double p5=new Point2D.Double(2782156.478,371784.0408);
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));
}
}