Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When your debugging something and you just CANT wrap your mind around whats going wrong... break it down into something easy to debug, throw out your hard test cases and try something very simple then move up to harder ones and find where it breaks, heres how i found it.</p> <p>I commented out all your code where you input the file and made your input to a fixed string:</p> <pre><code>String[] lineArray = ("3;2;" + "1 2 3 " + "6 5 4 ").split(";"); // see how the output should be 123456...very easy to see and debug </code></pre> <p>Putting a breakpoint at <code>while (maxX &gt; minX || maxY &gt; minY)</code>, I looked at the matrix array and saw that the matrix was of size 2x3 not 3x2, and my numbers were not stored how I would think they should be. And voila problem found.</p> <pre><code>/*if (maxY &gt;= maxX){*/ // This for loop is what you want for (int j = 0; j &lt;= maxY; j++){ for (int i = 0; i &lt;= maxX; i++){ matrix[i][j] = (valueArray[count]); count++; } } /*}/*delete this junk/ else if (maxX &gt; maxY){ for (int i = 0; i &lt;= maxX; i++){ for (int j = 0; j &lt;= maxY; j++){ matrix[i][j] = (valueArray[count]); count++; } } }*/ </code></pre> <p>This is a fun one for recursion. I assume you already submitted your code for your project so I took a stab at it. Heres what I ended up with: (I left in the printlns so you could see the program flow)</p> <pre><code>// called by System.out.println(getSpiral(matrix,0,0,0,0)); public static String getSpiral(String[][] array, int x, int y, double direction, int turnCount) { int [] velocity = getDirection(direction); if(x+velocity[0] &gt;= array.length || y+velocity[1] &gt;= array[x].length || x+velocity[0] &lt; 0 || y+velocity[1] &lt; 0 || array[x+velocity[0]][y+velocity[1]].equals("done")) { System.out.println("turn"); if(turnCount&gt;=3) return array[x][y]; return getSpiral(array, x, y, direction+Math.PI/2,turnCount+1); } String value = array[x][y].toLowerCase(); array[x][y]="done"; System.out.println(value); return value + " " + getSpiral(array, x+velocity[0], y+velocity[1], direction,0); } public static int[] getDirection(double angle) { return new int[] {(int)Math.round(Math.cos(angle)), (int)Math.round(Math.sin(angle))}; } </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.
    1. VO
      singulars
      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