forked from dimpeshmalviya/JavaBasicPrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiceSimulator.java
More file actions
25 lines (20 loc) · 773 Bytes
/
DiceSimulator.java
File metadata and controls
25 lines (20 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.Random;
import java.util.Scanner;
public class DiceSimulation {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();
String userInput;
System.out.println("🎲 Welcome to the Dice Simulator!");
do {
// Simulate a dice roll (1 to 6)
int diceRoll = random.nextInt(6) + 1;
System.out.println("You rolled: " + diceRoll);
// Ask user if they want to roll again
System.out.print("Roll again? (y/n): ");
userInput = scanner.nextLine().trim().toLowerCase();
} while (userInput.equals("y"));
System.out.println("Thanks for playing!");
scanner.close();
}
}