我有一個任務來製作井字遊戲的consol遊戲,但我有點卡住了。教師提供了編碼和驅動程序類的測試標準來測試我的TicTacToe.java。如果我在PlayTicTacToe.java的驅動程序類中運行以下,那麼所有的工作都很好。Java驅動程序類錯誤
TicTacToe ttt = new TicTacToe();
ttt.playGame();
但是,如果我使用教師提供的(下),我得到的錯誤,我不知道爲什麼。
Scanner s = new Scanner(System.in);
TicTacToe tictactoe = new TicTacToe('Sally', 'John');
System.out.print(「Would you like to play a game? Y/N: 」);
String play = s.nextLine();
while(play.equals('Y'))
{
tictactoe.playGame();
System.out.print(「Would you like to play a game? Y/N: 」);
play = s.nextLine();
}
TicTacToe tictactoe1 = new TicTacToe(「Sally」, 「John」);
TicTacToe tictactoe2 = new TicTacToe(「Sally」, 「John」);
// this will show true
System.out.println(tictactoe1.equals(tictactoe2));
// this will invoke the toString as shown above
System.out.println(tictactoe1);
我得到的錯誤是上線井字遊戲井字遊戲=新井字遊戲(「莎莉」,「約翰」);它會在'Sally'上產生一個紅色下劃線'錯誤的常量章程'錯誤
任何建議?
單個字符用單引號''y''表示。字符串使用雙引號'「John」'。所以用雙引號替換單引號。 – 2012-02-11 23:06:08