コードで問題が発生しました。答えが 9 であることはわかっていますが、私のコードでは 0 が出力され、その理由がわかりません。私はそれを実行するために2つのクラスを持っています。動作するかどうかを確認するためのメソッド クラスとテスター クラス。誰でも私のエラーを見つけることができますか?
public class Robot
{
private int[] hall;
private int pos;
private boolean facingRight;
private boolean forwardMoveBlocked()
{
if (facingRight)
{
return pos == hall.length - 1;
}
else
{
return pos == 0;
}
}
private void move()
{
if (hall[pos] > 0)
{
hall[pos]--;
}
if (hall[pos] == 0
{
if (forwardMoveBlocked())
{
facingRight = !facingRight;
}
else
{
if (facingRight)
{
pos++;
}
else
{
pos--;
}
}
}
}
public int clearHall()
{
int count = 0;
while (!hallIsClear())
{
move();
count++;
}
return count;
}
public boolen hallIsClear()
{
return true;
}
}
これが私のテスタークラスのコードです
public class Tester
{
public static void main(String[] args)
{
Robot RobotTest = new Robot();
System.out.println( RobotTest.clearHall() );
}
}