-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoinToss
More file actions
30 lines (24 loc) · 816 Bytes
/
Copy pathCoinToss
File metadata and controls
30 lines (24 loc) · 816 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
package cointoss;
import java.util.Random;
public class CoinToss {
public int tossACoin() {
Random rand = new Random();
int toss = Math.abs(rand.nextInt()) % 2;
if(toss == 0) {
System.out.println("this is an odd number ");
} else {
System.out.println("This is not an odd number :v ");
}
return toss;
}
public static void main(String[] args) {
// TODO code application logic here
CoinToss game = new CoinToss();
System.out.println(game.tossACoin());
System.out.println(game.tossACoin());
System.out.println(game.tossACoin());
System.out.println(game.tossACoin());
System.out.println(game.tossACoin());
System.out.println(game.tossACoin());
}
}