public class Dice
{
int player;
int computer;
public static void main (String[]args)
{
player = 1 + (int)((Math.random()*7));
computer = 1 + (int)((Math.random()*7));
diceRoll();
System.out.println("You rolled a " + player);
System.out.println("Computer rolled a " + computer);
System.out.println("And the winner is" + winner);
}
public static void diceRoll()
{
boolean winner = player > computer;
if (winner)
System.out.println("You won!");
if (!winner)
System.out.println("You lost!");
}
对不起......这可能是愚蠢的问题,但我很初学者的java
我应该创建一个骰子游戏。规则很简单,如果计算机的数量大于玩家的数量,则计算机获胜,如果玩家数量较多,则玩家获胜。我必须通过使用If语句创建此.. 但我得到的错误说“非静态变量不能从静态上下文中引用”,并且我得到错误说“找不到符号获胜者” 我不' t知道如何做到这一点.. 非常感谢你的帮助..模拟一个骰子游戏,非常初学者
因为你是内**主要使用类的全局变量(**播放**和** **电脑)()**和** diceRoll()**方法,其是**静**,那些类全局变量也需要是静态的。声明你的变量:'static int player;'和'static int computer;' – DevilsHnd