12 errors and 12 warnings found: -------------- *** Errors *** -------------- File: C:\Users\John\Documents\Computer Science\Summative\TicTacToe.java [line: 38] Error: Syntax error on token "int", @ expected File: C:\Users\John\Documents\Computer Science\Summative\TicTacToe.java [line: 38] Error: Syntax error, insert "enum Identifier" to complete EnumHeaderName File: C:\Users\John\Documents\Computer Science\Summative\TicTacToe.java [line: 38] Error: Syntax error, insert "EnumBody" to complete BlockStatement File: C:\Users\John\Documents\Computer Science\Summative\TicTacToe.java [line: 40] Error: Syntax error on token ",", . expected File: C:\Users\John\Documents\Computer Science\Summative\TicTacToe.java [line: 42] Error: Syntax error on token "int", @ expected File: C:\Users\John\Documents\Computer Science\Summative\TicTacToe.java [line: 42] Error: Syntax error, insert "enum Identifier" to complete EnumHeaderName File: C:\Users\John\Documents\Computer Science\Summative\TicTacToe.java [line: 42] Error: Syntax error, insert "EnumBody" to complete BlockStatement File: C:\Users\John\Documents\Computer Science\Summative\TicTacToe.java [line: 44] Error: Syntax error on token ",", . expected File: C:\Users\John\Documents\Computer Science\Summative\TicTacToe.java [line: 47] Error: Syntax error on token "int", @ expected File: C:\Users\John\Documents\Computer Science\Summative\TicTacToe.java [line: 47] Error: Syntax error, insert "enum Identifier" to complete EnumHeaderName File: C:\Users\John\Documents\Computer Science\Summative\TicTacToe.java [line: 47] Error: Syntax error, insert "EnumBody" to complete BlockStatement File: C:\Users\John\Documents\Computer Science\Summative\TicTacToe.java [line: 49] Error: Syntax error on token ",", . expected
这是我的代码
public class TicTacToe
{
public int winPoints1;
public int winPoints2;
public int losePoints1;
public int losePoints2;
public int tiePoints1;
public int tiePoints2;
public TicTacToe (int player1, int player2)
{
int winCombo[][] = new int[][]
{
{1, 2, 3}, {1, 4, 7}, {1, 5, 9},
{4, 5, 6}, {2, 5, 8}, {3, 5, 7},
{7, 8, 9}, {3, 6, 9}
};
for (int i = 0; i > 8;i++)
{
if (player2 == winCombo[i][0])
{
winPoints2++;
losePoints1++;
}
else
tiePoints2++;
if (player1 == winCombo[i][0])
{
winPoints1++;
losePoints2++;
}
else
tiePoints1++;
}
public int getWinPoints()
{
return winPoints1, winPoints2;
}
public int getLosePoints()
{
return losePoints1, losePoints2;
}
public int getTiePoints()
{
return tiePoints1, tiePoints2;
}
}
}
答案 0 :(得分:0)
Java没有实现从单个函数返回多个值。
如果您想要返回多个值,您的选择是
传递函数将修改的参数,并在外部函数中使用修改后的参数(请注意,int和所有基元都按值传递,不起作用)2)返回一个包含要返回的所有值的对象(例如,一个数组或整数的ArrayList)
答案 1 :(得分:0)
该代码中最明显的一点是Java不支持多个返回,因此您不能return tiePoints1, tiePoints2;
。您只能返回一个值。