点(x0,y0)和(x1,y1)之间的距离

use*_*391 0 java distance between points

我是编程的新手,并寻找帮助找到点之间的距离

我现在拥有的是:

import java.util.*;

class WS8Q2 {
public static void main(String[] args){
    Scanner in = new Scanner (System.in);

    double x0=0;
    double x1=0;
    double y0=0;
    double y1=0;

    System.out.println("Please enter 4 numbers");
    x0=in.nextDouble();

    double distance = (x0, y1, x1, y0);
    System.out.print(answer);
    }


    public static double distance (x0, y1, x1,y0) {
        return Math.Sqrt ((x1 - y0) * (y1-y0) + (x1-x0) * (x1-x0));
    }
Run Code Online (Sandbox Code Playgroud)

我真的不确定该怎么做,因为我以前从未做过距离,我只是完全失去了,试图查找某些公式,但我发现的唯一的东西似乎对我有用的是在这个网站链接哪个似乎对我说不多

编辑:这是问题和我想要实现的方式:

设计一个函数距离,它取四个分数参数x0,y0,x1和y1,并返回点(x0,y0)和(x1,y1)之间的距离.(如果你不记得它,请查看公式!)

Sag*_*age 10

两个点的距离公式(x0, y0),并(x1, y1)应为:

Math.Sqrt ((x1 - x0) * (x1-x0) + (y1-y0) * (y1-Y0));
Run Code Online (Sandbox Code Playgroud)

考虑接近OOP:声明一个带有(x,Y)属性的Point,声明一个setLocation(a, b)函数并声明getDistance(Point)函数:

class Point
{
   double x;
   double y;

   Point(double x, double y)
   {
      this.x = x;
      this.y = y;
  }

  public double getDistance(Point p)
  {
    // now implement it
  } 
}
Run Code Online (Sandbox Code Playgroud)

另外,如果你还没有意识到java有一个具有函数的Point2Ddistance(double px, double py).