-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoinflip.java
More file actions
31 lines (30 loc) · 952 Bytes
/
coinflip.java
File metadata and controls
31 lines (30 loc) · 952 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
30
31
import java.util.Random;
public class coinflip {
public static int randInt(int min, int max) {
Random rand = new Random();
int randomNum = rand.nextInt((max-min) +1) +min;
return randomNum;
}
public public static void main(String[] args) {
int heads = 0;
int tails = 0;
String num = args[0];
int coins = Integer.parseInt(num);
for(int i=1; i<=coins; i++) {
int theCoin = (randInt(1,50));
if (theCoin <= 25) {
String actualCoin = "H";
heads++;
System.out.print(actualCoin);
}
else {
String actualCoin = "T";
tails++;
System.out.print(actualCoin);
}
}
System.out.println();
System.out.println("HEADS " + heads);
System.out.println("HEADS " + tails);
}
}