求两点间的距离
给定 A(x1, y1),B(x2,y2) 两点坐标,计算它们间的距离。
输入格式
输入包含四个实数x1,y1,x2,y2,分别用空格隔开,含义如描述。
输出格式
输出占一行,包含一个实数 d,表示A,B 两点间的距离。结果保留两位小数。
数据范围
其中0≤x1,x2,y1,y2≤1000。
输出时每行末尾的多余空格,不影响答案正确性
样例输入
1 1 2 2
样例输出
1.41
具体解答:
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int [] number = new int[4];
for(int i=0;i<4;i++) {
number[i] = s.nextInt();
}
double x1,y1,x2,y2,result;
x1=number[0];y1=number[1];
x2=number[2];y2=number[3];
DecimalFormat df = new DecimalFormat("###0.00");
result = Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
System.out.print(df.format(result));
}
结果展示:

该博客介绍如何在JAVA中计算两点之间的距离,基于输入的两个坐标点(x1, y1)和(x2, y2),通过公式计算并输出保留两位小数的结果。"
111272956,10294142,Cocos Creator ETC1纹理压缩实践:解决全白问题,"['Cocos Creator', '纹理压缩', '图形内存优化', 'OpenGL ES', 'Android开发']

654

被折叠的 条评论
为什么被折叠?



