嘿,伙计们,我想知道是否有一种方法可以在不使用三元运算符的情况下通过使用 if 语句来编写此代码,这是我在 time 运算符时遇到的代码:
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);