返回列表 發帖
  1. import java.util.Scanner;


  2. public class JPA01 {
  3.    
  4. public static void main(String args[]){
  5.          Scanner scanner =new Scanner(System.in);
  6.          System.out.println("詩入第1組的x和y的座標");
  7.          float x1 = scanner.nextFloat();
  8.          float y1 = scanner.nextFloat();
  9.          System.out.println("詩入第2組的x和y的座標");
  10.          float x2 = scanner.nextFloat();
  11.          float y2 = scanner.nextFloat();
  12.          float xfar =x1-x2;
  13.          float yfar =y1-y2;
  14.          double far1 =Math.pow(xfar, 2)+Math.pow(yfar, 2) ;
  15.          double far2=Math.sqrt(far1);
  16.          System.out.printf("介於(%.2f,%.2f)和(%.2f,%.2f)之間的距離是%.2f",x1,y1,x2,y2,far2);
  17. }
  18. }
複製代碼

TOP

返回列表