/** * This program will play a simple dice game. * 7 you win, * any other number you loose * Method random from class Math is used to simulate * the roll of the dice. * * @author Anthony Larrain * @version July 2001 */ class DiceGame1{ public static void main( String arg []){ //this statement will assign to die1 one of the integers 1, 2, 3, 4, 5, 6 int die1 = (int)(Math.random() * 6 + 1); //this statement will assign to die2 one of the integers 1, 2, 3, 4, 5, 6 int die2 = (int)(Math.random() * 6 + 1); // result will contain either 2,3,4,5,6,7,8,9,10,11,12 int result = die1 + die2; System.out.println("You rolled .... " + result ); // if result is 7, execute the block of code to the if statement if(result == 7){ System.out.println("You won"); }else{ // if the result is not 7, execute this code. System.out.println("You lost"); } System.out.println("Good bye"); } }