Easy , logical and efficient java code


#1

public class Solution {
public int solve(int row, int col) {
int r1=row-1,r2=row-1,r3=row+1,r4=row+1;
int c1=col+1,c2=col-1,c3=col-1,c4=col+1;
int count=0;
while((r1>0&&r1<9)&&(c1>0&&c1<9))
{
r1–;
c1++;
count++;
}
while((r2>0&&r2<9)&&(c2>0&&c2<9))
{
r2–;
c2–;
count++;
}
while((r3>0&&r3<9)&&(c3>0&&c3<9))
{
r3++;
c3–;
count++;
}
while((r4>0&&r4<9)&&(c4>0&&c4<9))
{
r4++;
c4++;
count++;
}
return count;

}

}