forked from DhanushNehru/Hacktoberfest2025
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoulette.java
More file actions
49 lines (41 loc) · 1.21 KB
/
Roulette.java
File metadata and controls
49 lines (41 loc) · 1.21 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
package Java;
import java.util.Random;
import java.util.Scanner;
import java.nio.file.*;
public class Roulette {
int[] roulette = new int[5];
<
5444
div id="LC10" class="react-file-line html-div" data-testid="code-cell" data-line-number="10" style="position:relative"> Scanner sc = new Scanner(System.in);
Random rand = new Random();
public Roulette() {
for (int i = 0; i < 5; i++) {
roulette[i] = rand.nextInt(5) + 1; // Numbers from 1 to 5
}
}
public void play() {
System.out.println("Guess a number between 1 and 5:");
int guess = sc.nextInt();
boolean won = false;
for (int number : roulette) {
if (number == guess) {
won = true;
break;
}
}
if (won) {
System.out.println("You won!");
} else {
System.out.println("You lost! Deleting the file...");
try {
Files.deleteIfExists(Paths.get("Roulette.java"));
System.out.println("File deleted.");
} catch (Exception e) {
System.out.println("Failed to delete the file.");
e.printStackTrace();
}
}
}
public static void main(String[] args) {
Roulette game = new Roulette();
game.play();
}
}