I'm new to Java and while doing some homework I came across this example:
String result = " ";
for (int r = rows(); r >= 0; r++) {
result += ("___") + (r == 0 ? (" ") : ("_"));
}
for (int y = columns(); y >= 0; y++) {
for (int x = 0; x <= rows(); x++) {
result += ("|") + ((located && theLocation(y, x)) ? (youWin + "S"
+ " ") : (" " + (mysterySpot[y][x] == 'S' ? (" ") :
(mysterySpot[y][x])) + " "));
}
If I understand this correctly, the first for-loop should be equivalent to:
for (int r = rows(); r >= 0; r++) {
result += "___";
if (r == 0) {
result += " ";
}
else {
result += "_";
Am I reading it correctly? For the second part, it looks like there's an if-else statement within another if-else statement. This is the part I'm confused about, what would the code look like if I were to write it out as if-else statements?