-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDice
More file actions
84 lines (64 loc) · 1.72 KB
/
Dice
File metadata and controls
84 lines (64 loc) · 1.72 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// ********
// Dice.java
import java.util.Scanner;
public class Dice
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
String list= " 1- Four sided dice \n 2- Six sided dice \n 3- Eight sided dice \n 4- Twelve sided dice \n 5- Twenty sided dice \n 6- Quit \n Enter your choice";
System.out.println(list);
int n = scan.nextInt();
while (n != 6) {
switch (n) {
// 4 side dice
case 1: int die1;
die1 = (int)(Math.random() *4 + 1);
System.out.println("You rolled: " + die1);
System.out.println();
System.out.println(list);
n = scan.nextInt();
break;
// 6 side dice
case 2: int die2;
die2 = (int)(Math.random() *6 + 1);
System.out.println("You rolled: " + die2);
System.out.println();
System.out.println(list);
n = scan.nextInt();
break;
// 8 side dice
case 3: int die3;
die3 = (int)(Math.random() *8 + 1);
System.out.println("You rolled: " + die3);
System.out.println();
System.out.println(list);
n = scan.nextInt();
break;
// 12 side dice
case 4: int die4;
die4 = (int)(Math.random() *12 + 1);
System.out.println("You rolled: " + die4);
System.out.println();
System.out.println(list);
n = scan.nextInt();
break;
// 20 side dice
case 5: int die5;
die5 = (int)(Math.random() *20 + 1);
System.out.println("You rolled: " + die5);
System.out.println();
System.out.println(list);
n = scan.nextInt();
break;
// default
default:
System.out.println(" No dice. Roll again.");
System.out.println();
System.out.println(list);
n = scan.nextInt();
break;
}
}
}
}