Note that there are some explanatory texts on larger screens.

plurals
  1. POjava recursion on array
    primarykey
    data
    text
    <p>I have to create a program that finds all the possible ways of filling a square of size x by y. You place a block which takes up 2 spaces to completely fill. </p> <p>The problem is I don't know how to code it to the point where you can remember the placements of each square. I can get it to where it fills the board completely once and maybe twice, but nothing past that. I also know that I'm supposed to use recursion to figure this out . Here is the code I started on so far. There is also a main method and I have the initial even/odd check working fine. This is the part I have no idea on.</p> <pre><code> public void recurDomino(int row, int column) { if (Board[2][x - 1] != false) { } else if(Board[1][x-1]!=false) { } else { for (int n=0; n &lt; x - 1; n++) { Board[row][column] = true; Board[row][column+1] = true; column++; counter++; } recurDomino(1, 0); recurDomino(2, 0); } } Thank you for any help you guys can give me. ******************* EDIT **************************************** </code></pre> <p>I am a little confused still. I came up with this algorithm but I always get 2 for any value greater or equal to 2.</p> <pre><code>public boolean tryHorizontal(int row , int col){ if( row &lt; 0 || row &gt;= array[0].length-1) return false; else return true; } public boolean tryVertical(int row, int col){ if( col &lt; 0 || col &gt;= 2 ) return false; else return true; } public boolean tryRowCol(int row, int col){ if(this.tryHorizontal(row, col) &amp;&amp; this.tryVertical(row, col)){ return true; } else return false; } public int findWays(int row, int col){ int n = 0; if( !this.tryRowCol(row, col)) return 0; else n =+ 1 + this.findWays(row+1, col+1); return n; } </code></pre>
    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