summaryrefslogtreecommitdiff
path: root/src/Q9/MovingRobot.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Q9/MovingRobot.java')
-rw-r--r--src/Q9/MovingRobot.java20
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();