forked from dahuerfanov/custom-tilt5-localizer
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3coins.java
More file actions
22 lines (14 loc) · 916 Bytes
/
3coins.java
File metadata and controls
22 lines (14 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import java.util.Random;
public class CoinToss {
public static void main(String[] args) {
Random random = new Random();
// Simulate tossing three coins
boolean coin1 = random.nextBoolean(); // true for heads, false for tails
boolean coin2 = random.nextBoolean();
boolean coin3 = random.nextBoolean();
System.out.println("Coin 1: " + (coin1 ? "Heads" : "Tails"));
System.out.println("Coin 2: " + (coin2 ? "Heads" : "Tails"));
System.out.println("Coin 3: " + (coin3 ? "Heads" : "Tails"));
}
}
In this code, the Random class is used to generate random boolean values. nextBoolean() generates either true or false randomly. If it's true, it represents heads; if it's false, it represents tails. Each coin toss result is then printed to the console. Each time you run the program, you will get different random outcomes for the three coins.