I am fairly new to Java programming and I am having problems with creating a program with these requirements:
1. Create a program to simulate the roll of 2 – six sided dice.
2. Test to see if the dice are equal.
3a. If they are equal print “You win! You rolled a pair.
3b. If they are not equal prompt the user if they would like to continue.
4. Use 1 to continue and 2 to end the program.
5. When the program ends print a statement one of these statements:
You won after 9 rolls!
Or
You chose to end the game without winning after 8 tries.
If there is any help out there it would be greatly appreciated. I may be way off but below is what I currently have:
public class Dice {
public static void main(String[] args) {
// Welcome message.
System.out.println ("Welcome to The Dice Roller Game!");
// Roll the dice.
int die1, die2;
int rollcount;
rollcount = 0;
do {
die1 = (int)(Math.random()*6) + 1;
die2 = (int)(Math.random()*6) + 1;
rollcount++;
} while ( die1 != die2 );{
System.out.println("Would you like to roll again? 1 = Yes, 2 = No");
Scanner keyboard = new Scanner(System.in);
int userinput=keyboard.nextInt();
}
System.out.println("You won in " + rollcount + " rolls.");
}
}
Thank you for any help!