Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It is just a matter of looping through your array correctly. You need to think of it as a grid, and depending on how you look at it, determines how you print it: For example say you have a grid like, <code>char[3][4]</code> you could visualize it like:</p> <pre><code> 0 1 2 &lt;- this would be your columns 0 | | | | 1 | | | | 2 | | | | 3 |_|_|_| ^ | this would be your rows </code></pre> <p>Or you could visualize it like this:</p> <pre><code> 0 1 2 &lt;- this would be your columns 3 | | | | 2 | | | | 1 | | | | 0 |_|_|_| ^ | this would be your rows </code></pre> <p>So it depends on where you think the the item at <code>(0,0)</code> is located. The following example assumes that <code>(0,0)</code> is located at the bottom right:</p> <pre><code>public class BeanMachine { static final char BALL = 'O'; static char[][] slots; public static void main(String[] args) { int height = 10; int width = 5; slots = new char[height][width]; // just adding some stuff in here so we have something to print slots[0][0] = BALL; // bottom left slots[9][4] = BALL; // top right displayBoard(); } static void displayBoard() { // we need to loop through each row String columnSeperator = "|"; for (int i = slots.length - 1; i &gt;= 0; i = i - 1) { String row = columnSeperator; for (int j = 0; j &lt; slots[i].length; j = j + 1) { // char seems to be initialized to ' ' so we do not need to do // any checks and just add the value in the array. row = row + slots[i][j] + columnSeperator; } System.out.println(row); } } } </code></pre>
 

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