Just use a if
condition.
if (i == 1) {
animal = "dog";
} else if (i == 2) {
animal = "cat";
}
Some additional comments:
- I would recommend using
Enum
instead ofString
. - This:
for(int puzzleNum = 1; puzzleNum <= NUMANIMALS; mazeNum++)
looks like an infinite loop to me, as yourpuzzleNum
doesn’t change in the loop at all.
4
solved How to change what a string equals in a forloop [closed]