Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a couple of ways to do this. The simplest I can think of is to remove the loops from the <code>populateRandom()</code> function (and maybe name it something else) and call it inside the inner most loop in <code>drawGrid()</code></p> <pre><code>static char[] options = { '*', '$', '@', '+', '!', '&amp;' }; public static void main(String[] args) { System.out .println("How to play: type a row and column index, followed by \n" + "the direction to move it: u (up), r (right), d (down), l (left)"); char[][] grid = new char[8][8]; drawGrid(grid); System.out .println("Enter &lt;row&gt; &lt;column&gt; &lt;direction to move&gt; or q to quit"); // char randomChar = 66; // System.out.println(randomChar); } public static void drawGrid(char[][] grid) { System.out.println("\t1 \t2 \t3 \t4 \t5 \t6 \t7 \t8"); System.out.println(); // Random r = new Random(); for (int row = 0; row &lt; grid.length; row++) { // populateRandom(grid,options); System.out.print((row + 1) + ""); for (int column = 0; column &lt; grid[row].length; column++) { populateRandom(grid[row][column]); } System.out.println(); } System.out.println(); } public static void populateRandom(char grid) { Random randomGenerator = new Random(); int randomIndex = randomGenerator.nextInt(6); grid = options[randomIndex]; System.out.print("\t" + grid); } public static boolean isWithinGrid(int row, int col, String cmd, char[][] grid) { return true; } public static void swap(int row, int col, String cmd, char[][] grid) { } public static boolean updateGrid(char[][] grid, char[] options) { return false; } </code></pre> <p>The problem with what you are doing is that, on console, once you go to a new line, you can't go back and print more stuff on the previous line (actually you can but it's really cumbersome and pointless).</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.
    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