- import java.util.Scanner;
- public class JPA01 {
-
- public static void main(String args[]){
- Scanner scanner =new Scanner(System.in);
- System.out.println("詩入第1組的x和y的座標");
- float x1 = scanner.nextFloat();
- float y1 = scanner.nextFloat();
- System.out.println("詩入第2組的x和y的座標");
- float x2 = scanner.nextFloat();
- float y2 = scanner.nextFloat();
- float xfar =x1-x2;
- float yfar =y1-y2;
- double far1 =Math.pow(xfar, 2)+Math.pow(yfar, 2) ;
- double far2=Math.sqrt(far1);
- System.out.printf("介於(%.2f,%.2f)和(%.2f,%.2f)之間的距離是%.2f",x1,y1,x2,y2,far2);
- }
- }
複製代碼 |