Java库中的Point2D类


javafx.geometry.Point2D

+Point2D(x: double,y: double) //用给定的x和y坐标来创建一个Point2D对象

+distance(x: double,y: double): double //返回该点到定点(x,y)的距离

+distance(p: Point2D): double //返回该点到p点的距离

+getX(): double //返回该点的x的坐标

+getY(): double //返回该点的y的坐标

+toString(): String //返回该点的字符串表示

import java.util.Scanner;
import javafx.geometry.Point2D;
public class TestPoint2D {
public static void main(String[] args){
	
	Scanner input= new Scanner(System.in);
	System.out.println("Enter point1's x-,y-coordinates:");
	double x1=input.nextDouble();
	double y1=input.nextDouble();
	System.out.println("Enter point2's x-,y-coordinates:");
	double x2=input.nextDouble();
	double y2=input.nextDouble();
	Point2D p1 =new Point2D(x1,y1);
	Point2D p2 =new Point2D(x2,y2);
	System.out.println("p1 is"+p1.toString());
	System.out.println("p2 is"+p2.toString());
	System.out.println("distance is"+p1.distance(p2));
	} 
}
复制代码

为什么会把这个类单拿出来呢,因为在eclipse运行的时候,你会发现会报错,难道是书写错了?不不不,下面是答案:

这是因为这个类是Eclipse的JRE带的,但并不属于JAVA的公开API。

解决方法:

右击项目->属性->Java Compiler->Errors/Warnings->Deprecated and restricted API->Forbidden reference -> Ignore

运行结果

Enter point1's x-,y-coordinates:
1 2
Enter point2's x-,y-coordinates:
3 4
p1 isPoint2D [x = 1.0, y = 2.0]
p2 isPoint2D [x = 3.0, y = 4.0]
distance is2.8284271247461903
复制代码

转载于:https://juejin.im/post/5ad8b4e2f265da0b981afd7a

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值