你有兩個名稱相同的對象,看point
是一個點陣列,那麼point
是我猜的字符串!
你認爲的:
points = Point array
和
point = the current point
嘗試這樣的:
import java.awt.Point;
public class Dice{
public static Point[] point;
public static boolean check(Point _point){ // Here _point is being searched in point array.
int particle;
for(particle = 0; particle < point.length; particle++){
System.out.println("Comparing "+ point[particle].getX() + " and " +_point.getX());
System.out.println("Comparing 2 "+ point[particle].getY() + " and " +_point.getY());
if(point[particle].getX() == _point.getX() && point[particle].getY() == _point.getY()){ //
return true; // if _point is into the array
}
}
return false;
}
public static void main(String a[]) {
point = new Point[10];
for(int i= 0; i < point.length; i++)
point[i] = new Point(10, i);
System.out.println(check(new Point(10, 5)));
}
}
但是,如果點是整個陣列和點[顆粒]爲當前點那麼它應該工作當不可它呢? – user1610541
問題是兩者都具有相同的名稱。重命名其中一個! – slackmart
因爲它們是一樣的東西!我試圖查看當前點是否等於已存儲的點。 – user1610541