Note that there are some explanatory texts on larger screens.

plurals
  1. POgetting the edge value of a 2D array while preventing getting out of bounds
    primarykey
    data
    text
    <p>I have 4x4 character array here and I need to get the common value of the character that is on the edge of the array...I tried the solutions from other questions similar to my problem, but I am still getting the same error., </p> <p>here's my code..</p> <pre><code>//arr2[][] // arr2[3][0] = 'H'; // arr2[3][1] = 'E'; // arr2[3][2] = 'L'; // arr2[3][3] = 'P'; //arr3[][] // arr3[1][3] = 'T'; // arr3[2][3] = 'O'; // arr3[3][3] = 'P'; //I specifically need the get the 'P' at [3][3].. for(o = 0;o&lt;count;o++){ char letter = out.charAt(o); for(int m = 0; m &lt; 4; m ++){ for(int n = 0; n &lt; 4; n ++){ if(Arrays.asList(arr3[m][n]).contains(letter)){ r = m; c = n; } } } right = arr2[r][c+1]; left = arr2[r][c-1]; up = arr2[r-1][c]; down = arr2[r+1][c]; if(o==0){ if(c==0){ if(r==0||r==3){ if(right!=null){ l = right; } }else{ if(right!=null){ l = right; }else if(up!=null){ l = up; } } }else if(c==3){ if(r==0||r==3){ if(left!=null){ l = left; } }else{ if(left!=null){ l = left; }else if(up!=null){ l = up; } } }else{ if(r==0||r==3){ if(left!=null){ l = left; }else if(right!=null){ l = right; } }else{ if(left!=null){ l = left; }else if(right!=null){ l = right; }else if(up!=null){ l = up; } } } } }else if(o==(count-1)){ if(vertical == 1){ if(c==0){ if(r==0||r==3){ if(right!=null){ l = right; } }else{ if(right!=null){ l = right; }else if(down!=null){ l = down; } } }else if(c==3){ if(r==0||r==3){ if(left!=null){ l = left; } }else{ if(left!=null){ l = left; }else if(down!=null){ l = down; } } }else{ if(r==0||r==3){ if(left!=null){ l = left; }else if(right!=null){ l = right; } }else{ if(left!=null){ l = left; }else if(right!=null){ l = right; }else if(down!=null){ l = down; } } } } }else{ if(vertical == 1){ if(c==0){ if(right!=null){ l = right; } }else if(c==3){ if(left!=null){ l = left; } }else{ if(right!=null){ l = right; }else if(left!=null){ l = left; } } } } k = Character.toString(letter); letr = Character.toString(l); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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