toString() : Overrides Object toString() . Returns a String representation of th
ID: 3677912 • Letter: T
Question
toString(): Overrides Object toString(). Returns a String representation of the maze as shown above.
How do i return the value this gives? I get the error String required but I have a char. I would like to know how to return the String representation of it.
public String toString()
{
for (int i = 0; i<map.length;i++)
{
for (int y = 0; y <map[i].length;y++)
{
System.out.print(map[i][y]);
}
System.out.println("");
}
return ????
}
Explanation / Answer
// -----------------------------------------------------------------
// Returns the maze as a string.
// -----------------------------------------------------------------
public String toString() {
String result = " ";
// row of maze
for (int i = 0; i < map.length; i++) {
// column of maze
for (int y = 0; y < map[i].length; y++)
result += map[i][y] + "";
result += " ";
}
return result;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.