嘿家伙,我想知道如果用如果这里声明是在时代运营商难倒代码IM有写这不使用三元运营商的一种方式:三元运营商,以“if”语句
int x1 = place.getX();
int x2 = x1 +
((direction == direction.NORTH || direction == direction.SOUTH ? shipLength : shipWidth) - 1) *
(direction == direction.NORTH || direction == direction.EAST ? -1 : 1);
int y1 = place.getY();
int y2 = y1 +
((direction == direction.NORTH || direction == direction.SOUTH ? shipWidth : shipLength) - 1) *
(direction == direction.WEST || direction == direction.NORTH ? -1 : 1);
是的,你可以用if/then构造来代替三元组。 – wildplasser