I have a dice game to need to creat that plays until the total of the two die equals the users number, or the two die roll 3 total times. I also need to display the die after each roll. Something like this:
Six: Five: and so on...
* * * *
* * *
* * * *
I have gotten it roll stop rolling after 3 times but I'm not sure about the rest.
import java.util.Scanner; //Needed for Scanner class
public class Dice
{
public static void main(String[] args)
{
int user; //Input from user between 2 and 12
int die1; //Roll of die 1
int die2; //Roll of die 2
int total=0; //Total of the two die rolled
int roll = 0; //number of rolls for increment
//Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
//Get the number entered by user.
System.out.print("Please enter a number between 2 and 12. ");
user = keyboard.nextInt();
do {
//roll die.
die1 = (int)(Math.random()*6) + 1; //first die rolled
die2 = (int)(Math.random()*6) + 1; //second die rolled
total = die1 + die2; //total of two rolls
roll = roll + 1;
//print out the result
System.out.println("Your first roll is a: " + die1);
System.out.println("Your second roll is a: " + die2);
System.out.println("Your total is: " + total);
System.out.println();
}while(roll<3);
}
}