-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiceRoller.java
More file actions
29 lines (24 loc) · 812 Bytes
/
DiceRoller.java
File metadata and controls
29 lines (24 loc) · 812 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
26
27
28
29
import java.util.Random;
import java.util.Scanner;
public class DiceRoller {
public static void main(String[] args) {
// Dice Roller Program
Scanner scanner = new Scanner(System.in);
Random random = new Random();
int numOfDice;
int total = 0;
System.out.print("Enter the number of dice to roll: ");
numOfDice = scanner.nextInt();
if(numOfDice > 0) {
for(int i = 0; i < numOfDice; i++) {
int roll = random.nextInt(1,7);
System.out.println("You rolled: " + roll);
total += roll;
}
System.out.println("Total: " + total);
} else {
System.out.println("Number of dice must be greater than zero.");
}
scanner.close();
}
}