我这里有 4x4 字符数组,我需要获取位于数组边缘的字符的共同值...我尝试了与我的问题类似的其他问题的解决方案,但我仍然遇到相同的错误。,
这是我的代码..
//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<count;o++){
char letter = out.charAt(o);
for(int m = 0; m < 4; m ++){
for(int n = 0; n < 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);