首页 > 试题广场 >

(几何:两点间距离)编写程序,提示用户输人两个点(x1, y

[问答题]
(几何:两点间距离)编写程序,提示用户输人两个点(x1, y1) 和(x2, y2), 然后显示两点间 的 距 离。计 算 两 点 间 距 离 的 公 式 是  注意:可 以 使 用 Math.pow(a,0.5) 来计算。下面是一个运行示例: 

package AA;
import java.util.Scanner;
public class ah {
    public static void main(String[] args){
           double x1,y1,x2,y2;
           System.out.print("Enter x1 and y1:");
           Scanner in=new Scanner(System.in);
           x1=in.nextDouble();
           y1=in.nextDouble();
           System.out.print("Enter x2 and y2:");
           Scanner s=new Scanner(System.in);
           x2=s.nextDouble();
           y2=s.nextDouble();
           double l=0;
           l=Math.pow(Math.pow(x2-x1, 2)+Math.pow(y2-y1, 2), 0.5);
           System.out.print("The distance between the two points is"+" "+l);
           
    }

}
发表于 2021-04-06 15:42:38 回复(0)