本帖最後由 王彥甯 於 2016-12-10 11:40 編輯
- 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 x1 = scanner.nextFloat();
- float y1 = scanner.nextFloat();
- System.out.print("輸入第二組X和Y座標:");
- float x2 = scanner.nextFloat();
- float y2 = scanner.nextFloat();
- float result = (float)(Math.pow(x2-x1, 2)+Math.pow(y2-y1, 2));
- float distance = (float) Math.sqrt(result);
- System.out.printf("介於(%.2f , %.2f)和(%.2f , %.2f)之間的距離是%.2f",x1,y1,x2,y2,distance);
- }
- }
複製代碼 |