求两个坐标点之间的距离,注意打印的小数点位数就好。
/** * 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)); } } }