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