1. 程式人生 > >計算兩點距離

計算兩點距離

() ner oid clas java next 技術 ima n)

import java.util.Scanner;
  public class Jisuanjl{
  public static void main(String[] args){
    Scanner input=new Scanner(System.in);
    System.out.print("Enter x1 and y1:");
    double x1=input.nextDouble();
    double y1=input.nextDouble();
    Scanner input1=new Scanner(System.in);
    System.out.print("Enter x2 and y2:");
    double x2=input1.nextDouble();
    double y2=input1.nextDouble();
    double l=Math.sqrt(Math.pow((x2-x1),2)+Math.pow((y2-y1),2));
    System.out.println("The distance between the two point is "+l);

  }
}

技術分享

計算兩點距離