Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>else if (x &lt;= b.length &amp;&amp; y &lt;= b[x].length &amp;&amp; x &lt;= a.length &amp;&amp; y &lt;= a[x].length) { merged[x][y] = ((a[x][y] + b[x][y]) /2); // &lt;= problematic line } </code></pre> <p>in this line you try to reach a point where it's out of a's bound. In my example, i set a to be <code>(10, 10)</code> and b to be <code>(5, 20)</code>. It crashed when <code>x = 0, y = 10</code>. Now, as you can see <code>a[0][10]</code> is out of bounds. </p> <p>Here is my trial code and it's output:</p> <pre><code>else if (x &lt;= b.length &amp;&amp; y &lt;= b[x].length &amp;&amp; x &lt;= a.length &amp;&amp; y &lt;= a[x].length) { System.out.println("x = " + x + " y = " + y); System.out.println("merged.length = " + merged.length); System.out.println("merged[0].length = " + merged[0].length); System.out.println("a.length = " + a.length); System.out.println("a[0].length = " + a[0].length); System.out.println("b.length = " + b.length); System.out.println("b[0].length = " + b[0].length); System.out.println(); System.out.println(); merged[x][y] = ((a[x][y] + b[x][y]) /2); } </code></pre> <p>Output:</p> <pre><code>x = 0 y = 10 merged.length = 10 merged[0].length = 20 a.length = 10 a[0].length = 10 b.length = 5 b[0].length = 20 </code></pre> <p>EDIT: Just noticed solution I proposed is not applicable for you.</p> <p>EDIT2: <code>x &lt;= a.length</code> and <code>y &lt;= a[x].length</code> kind of statements needs to be changed into <code>x &lt; a.length</code> and <code>y &lt; a[x].length</code> or <code>x &lt;= a.length - 1</code> and <code>y &lt;= a[x].length - 1</code></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.
 

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