//我知道坐标不正确,我会在合规后修复它们,但我不明白为什么它一直给我这条消息
public class DiceRoller
Public static void main(String[] args
{
if (dice1 == 1)
StdDraw.square(.5, .4, .2);
StdDraw.circle(.3, .5, .035);
else if (dice1 == 2)
StdDraw.square(.5, .4, .2);
StdDraw.circle(.3, .45, .035);
StdDraw.circle(.3, .55, .035);
else if (dice1 == 3)
StdDraw.square(.5, .4, .2);
StdDraw.circle(.3, .55, .035);
StdDraw.circle(.3, .45, .035);
StdDraw.circle(.3, .50, .035);
else if (dice1 == 4)
StdDraw.square(.5, .4, .2);
StdDraw.circle(.25, .55, .035);
StdDraw.circle(.25, .40, .035);
StdDraw.circle(.75, .55, .035);
StdDraw.circle(.75, .40, .035);
else if (dice1 == 5)
StdDraw.square(.5, .4, .2);
StdDraw.circle(.25, .55, .035);
StdDraw.circle(.25, .40, .035);
StdDraw.circle(.75, .55, .035);
StdDraw.circle(.75, .55, .035);
StdDraw.circle(.3, .5, .035);
else if (dice1 == 6)
StdDraw.square(.5, .4, .2);
StdDraw.circle(.25, .50, .035);
StdDraw.circle(.25, .60, .035);
StdDraw.circle(.25, .40, .035);
StdDraw.circle(.75, .60, .035);
StdDraw.circle(.75, .40, .035);
StdDraw.circle(.75, .50, .035);
if (dice2 == 1)
StdDraw.square(.5, .7, .2);
StdDraw.circle(.3, .5, .035);
else if (dice2 == 2)
StdDraw.square(.5, .7, .2);
StdDraw.circle(.3, .45, .035);
StdDraw.circle(.3, .55, .035);
else if (dice2 == 3)
StdDraw.square(.5, .7, .2);
StdDraw.circle(.3, .55, .035);
StdDraw.circle(.3, .45, .035);
StdDraw.circle(.3, .50, .035);
else if (dice2 == 4)
StdDraw.square(.5, .7, .2);
StdDraw.circle(.25, .55, .035);
StdDraw.circle(.25, .40, .035);
StdDraw.circle(.75, .55, .035);
StdDraw.circle(.75, .40, .035);
else if (dice2 == 5)
StdDraw.square(.5, .7, .2);
StdDraw.circle(.25, .55, .035);
StdDraw.circle(.25, .40, .035);
StdDraw.circle(.75, .55, .035);
StdDraw.circle(.75, .55, .035);
StdDraw.circle(.3, .5, .035);
else if (dice2 == 6)
StdDraw.square(.5, .7, .2);
StdDraw.circle(.25, .50, .035);
StdDraw.circle(.25, .60, .035);
StdDraw.circle(.25, .40, .035);
StdDraw.circle(.75, .60, .035);
StdDraw.circle(.75, .40, .035);
StdDraw.circle(.75, .50, .035);
}
最佳答案
您需要将 if
放在括号 {}
内,如下所示:
if (dice1 == 2)
{ //should be enclosed since there are more than one statement to be executed
StdDraw.square(.5, .4, .2);
StdDraw.circle(.3, .45, .035);
StdDraw.circle(.3, .55, .035);
}
关于java - 错误: 'else' without 'if - Cant find solution,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32753616/