Sunday, 16 December 2012
A Java Program That Rolls A Pair OF Dice and Sums Up the Outcomes. Now Who Wants To Gamble ;)
import java.util.Scanner;
public class DiceRoll
{
private static final int dice = 6;
public static void main( String[] args )
{
Scanner input = new Scanner( System.in );
int x = 0;
int y = 0;
int z = 0;
/*Rolls and sums up outcome of Dice till the loop breaks if 7 is entered at
prompt*/
while ( z != 7 ) {
System.out.println( "Press Any Number To Roll First Die" );
x = input.nextInt();
x = (int) (Math.random() * dice) + 1;
System.out.println( "First Roll = " + x );
System.out.println( "Press Any Number To Roll Second Die" );
y = input.nextInt();
y = (int) (Math.random() * dice) + 1;
System.out.println( "Second Roll = " + y );
System.out.println( "You Rolled a " + (x + y) + "\n" );
System.out.println( "Press 7 To quit Or Any Number To Keep On Rolling" );
z = input.nextInt();
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment