package main;
import java.util.Scanner;
public class Second{
private static Scanner input;
public static void main(String args[]){
input = new Scanner(System.in);
MyPoint op1 = new MyPoint();
MyPoint op2 = new MyPoint(input.nextDouble(),input.nextDouble());
System.out.println("The distance1 is "+op1.distance(op2));
System.out.println("The distance2 is "+op2.distance(0, 0));
}
}
class MyPoint{
private double x;
private double y;
public MyPoint()
{
this.x = 0;
this.y = 0;
}
public MyPoint(double x, double y)
{
this.x = x;
this.y = y;
}
public double getX()
{
return this.x;
}
public double getY()
{
return this.y;
}
public double distance(MyPoint myPoint)
{
double s;
s = Math.sqrt((this.x - myPoint.getX()) * (this.x - myPoint.getX())
+(this.y - myPoint.getY()) * (this.y - myPoint.getY()));
return s;
}
public double distance(double x,double y)
{
double s;
s = Math.sqrt((this.x - x) * (this.x - x)
+(this.y - y) * (this.y - y));
return s;
}
}
设计一个名为MyPoint的类
最新推荐文章于 2024-05-05 22:58:49 发布