平方根运算

import java.util.Scanner;

public class SquareRoot{
public static void main(String[] args) {
System.out.println("请输入两点坐标:");
Scanner sc=new Scanner(System.in);
double x1,x2,y1,y2;
double l;
while (sc.hasNext()){
x1=sc.nextDouble();
y1=sc.nextDouble();
x2=sc.nextDouble();
y2=sc.nextDouble();
l=Math.sqrt(Math.pow((x1-x2),2)+Math.pow((y1-y2),2));//Math.sqrt返回一个数的平方根,Math.pow返回一个数的平方
System.out.println("两点之间的距离:"+String.format("%.2f",l));
}

}
}

猜你喜欢

转载自www.cnblogs.com/chenjiajiale/p/12502490.html
今日推荐