求两个坐标点之间的距离,注意打印的小数点位数就好。
/** * Created by YangYuan on 2017/12/8. */ public class Problem2001 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { double x1 = scanner.nextDouble(); double y1 = scanner.nextDouble(); double x2 = scanner.nextDouble(); double y2 = scanner.nextDouble(); double distance = Math.pow((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2), 0.5); DecimalFormat df = new DecimalFormat("0.00"); System.out.println(df.format(distance)); } } }

本文提供了一个简单的Java程序,用于计算二维平面上任意两点之间的欧几里得距离,并精确到小数点后两位。

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



