-
Notifications
You must be signed in to change notification settings - Fork 0
/
LabNo5.java
43 lines (37 loc) · 1.01 KB
/
LabNo5.java
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
package testing;
import java.util.Random;
import java.util.Scanner;
public class LabNo5 {
public static int rollDice(int numOfSides) {
Random rand = new Random();
int result;
result = rand.nextInt(numOfSides) + 1;
return result;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int numOfSides, numOfDice;
boolean again;
do {
again = false;
System.out.println("Please, enter the number of sides of a dice you want to roll: ");
numOfSides = scan.nextInt();
System.out.println("How many dice you want to roll?");
numOfDice = scan.nextInt();
System.out.println("Good! Here's your rolls:");
for (int i = 0; i < numOfDice; i++) {
System.out.print((i + 1) + ": ");
System.out.println(rollDice(numOfSides));
}
scan.nextLine();
System.out.println("Do you want to do it again? (y/n)");
if (scan.nextLine().equals("y"))
again = true;
else {
System.out.println("Bye!");
break;
}
} while (again);
scan.close();
}
}