嘿傢伙,我想知道如果用如果這裏聲明是在時代運營商難倒代碼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