1
이 줄은 '현재 컨텍스트에서 알 수없는'컴파일러 오류를 생성합니다. 왜?java : 현재 컨텍스트에서 변수를 알 수 없습니까?
if (inputMatrix[newPosition.i][newPosition.j]=='*'){
// variable not known in current context, why?
}
방법 선언 :
static Point moveForward(Point oldPosition, int matrixSize, char orientation, char [][] inputMatrix){
// add possible new Position
Point newPosition;
//first return oldPosition border positions in which the robot shouldn't move
if ((orientation=='O')&&(oldPosition.j==0))
return oldPosition;
if ((orientation=='E')&&(oldPosition.j==(matrixSize-1)))
return oldPosition;
if ((orientation=='N')&&(oldPosition.i==0))
return oldPosition;
if ((orientation=='S')&&(oldPosition.i==(matrixSize-1)))
return oldPosition;
if ((orientation=='O'))
newPosition = new Point(oldPosition.i, oldPosition.j-1);
if ((orientation=='E'))
newPosition = new Point(oldPosition.i, oldPosition.j+1);
if ((orientation=='S'))
newPosition = new Point(oldPosition.i-1, oldPosition.j);
if ((orientation=='N'))
newPosition = new Point(oldPosition.i+1, oldPosition.j);
//then return oldPosition for positions in which the robot is blocked by *
if (inputMatrix[newPosition.i][newPosition.j]=='*'){
// variable not known in current context, why?
}
return null;
}