gpt4 book ai didi

java - 点 isAbove, isUnder, isRight, isLeft 方法

转载 作者:行者123 更新时间:2023-12-04 19:33:46 24 4
gpt4 key购买 nike

这是我的积分等级;

public class Point
{
private int _x;
private int _y;

public boolean isAbove (Point other)
{
if (_y <= other._y)
return false;
else
return true;
}

public boolean isUnder (Point other)
{
return isAbove(other);
}

public boolean isLeft (Point other)
{
if (_x >= other._x)
return false;
else
return true;
}

public boolean isRight (Point other)
{
return isLeft(other);
}
}

以上所有方法都没有按预期运行,我找不到我做错了什么。例如:

Point pp1 = new Point(1, 0);
Point pp2 = new Point(0, 0);
System.out.println("isAbove: " + pp1.isAbove(pp2));
System.out.println("isUnder: " + pp1.isUnder(pp2));
System.out.println("isLeft : " + pp1.isLeft(pp2));
System.out.println("isRight: " + pp1.isRight(pp2));

全部返回false。

最佳答案

试试这个,它应该工作:

public boolean isAbove (Point other)
{
return _y > other._y;
}

public boolean isUnder (Point other)
{
return other.isAbove(this);
}

public boolean isLeft (Point other)
{
return _x < other._x;
}

public boolean isRight (Point other)
{
return other.isLeft(this);
}

关于java - 点 isAbove, isUnder, isRight, isLeft 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20214700/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com