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