diff options
| author | mo khan <mo@mokhan.ca> | 2019-08-05 13:15:14 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2019-08-05 13:15:14 -0600 |
| commit | 151b106f5d265f17ccf38e978c197e1e38dc4deb (patch) | |
| tree | a3ef81ee204ef9015990b39c9712abdb0372c2d0 /src/Q9/MovingRobot.java | |
| parent | 3b7c58abefca9db8b1b3431e308fccbe5eeab1e9 (diff) | |
print full 10x10 grid
Diffstat (limited to 'src/Q9/MovingRobot.java')
| -rw-r--r-- | src/Q9/MovingRobot.java | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/Q9/MovingRobot.java b/src/Q9/MovingRobot.java index 391f407..3cbccaa 100644 --- a/src/Q9/MovingRobot.java +++ b/src/Q9/MovingRobot.java @@ -47,18 +47,17 @@ public class MovingRobot extends Robot { public static String printGrid(Robot x, Robot y) { String grid = ""; - int row = 0; - - for (int column = 0; column < 10; column++) { - if (x.getX() == row && x.getY() == column) { - grid += "|X"; - } else if (y.getX() == row && y.getY() == column) { - grid += "|Y"; - } else { - grid += "| "; + for (int row = 0; row < 10; row++) { + for (int column = 0; column < 10; column++) { + if (x.getX() == row && x.getY() == column) + grid += "|X"; + else if (y.getX() == row && y.getY() == column) + grid += "|Y"; + else + grid += "| "; } + grid += "|\n"; } - grid += "|\n"; return grid; } @@ -149,6 +148,7 @@ public class MovingRobot extends Robot { public static void main(String[] args) { MovingRobot r1 = new MovingRobot(0, 0); MovingRobot r2 = new MovingRobot(9, 9); + while (!MovingRobot.sameSlot(r1, r2)) { r1.move(); r2.move(); |
