TQC+ JAVA104 距離計算
import java.util.*;
import java.math.*;
public class JPA01 {
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
double x1,x2,y1,y2;
System.out.print("輸入第1組的x和y座標:");
x1=keyboard.nextDouble();
y1=keyboard.nextDouble();
System.out.print("輸入第2組的x和y座標:");
x2=keyboard.nextDouble();
y2=keyboard.nextDouble();
double di;
di=Math.sqrt(Math.pow(x1-x2, 2)+Math.pow(y1-y2, 2));
System.out.printf("介於(%.2f,%.2f)和(%.2f,%.2f)之間的距離是%.2f。", x1,x2,y1,y2,di);
}
}
import java.math.*;
public class JPA01 {
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
double x1,x2,y1,y2;
System.out.print("輸入第1組的x和y座標:");
x1=keyboard.nextDouble();
y1=keyboard.nextDouble();
System.out.print("輸入第2組的x和y座標:");
x2=keyboard.nextDouble();
y2=keyboard.nextDouble();
double di;
di=Math.sqrt(Math.pow(x1-x2, 2)+Math.pow(y1-y2, 2));
System.out.printf("介於(%.2f,%.2f)和(%.2f,%.2f)之間的距離是%.2f。", x1,x2,y1,y2,di);
}
}
沒有留言:
張貼留言