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!"); }
Sorry ... this might be a dumb question, but I'm very new to java
I have to create a dice game. The rule is simple, if the computer has more than the player, then the computer wins, and if the player has a larger number, the player wins. I have to create this using the If statement .. But I get a message stating that "a non-stationary variable cannot be specified from a static context", and also I got an error message "cannot find a character winner", I donβt know how to do it. Thank you so much for your help.
source share