Note that there are some explanatory texts on larger screens.

plurals
  1. POJAVA : How can I represent a 2D character array as a String using a toString ?
    primarykey
    data
    text
    <p>I am making a program using the LRV(Least recently visited) Algorithm. Basically, I design the algorithm for a robot to traverse through a grid (which is a 2D char array). The robot whilst traversing the grid checks whether each cell is either EMPTY (defined by '-'), OCCUPIED ( defined by 'O' ) or BLOCKED (defined by 'X'). The cells can only be occupied by an object known as Sensor (this has its own class). BLOCKED cells cannot be traversed on. Each time the robot must move, it receives a direction from the sensor. So in the beginning the robot would be placed on the grid and it would drop a sensor and get a direction from it, or get a direction from a pre-existing sensor.</p> <p>Now that I've explained my program, my specific question is, I have my GridMap class</p> <pre><code>public class GridMap { private int height; private int width; private char[][] grid; public GridMap(int x, int y) { height=x; width=y; grid = new char [x][y]; } public int getHeight(){ return height; } public int getWidth(){ return width; } public String toString(){ String s1 = return s1; } public char getElementAt(int x, int y){ } public void setElementAt(int x, int y){ } public boolean isCellBlocked(int x, int y){ } public double getCoverageIndex(){ return COVERAGE_INDEX; } } </code></pre> <p>What I want to know is how can I represent my 2D char array as a string of -, O's and X's. I tried to be as detailed as possible, if anyone has any questions I'd be willing to answer asap. Any help will be highly appreciated. Thanks</p> <p>Varun</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload