-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise03_14
More file actions
37 lines (34 loc) · 914 Bytes
/
Copy pathExercise03_14
File metadata and controls
37 lines (34 loc) · 914 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
32
33
34
35
36
37
import java.util.Scanner;
public class Exercise03_14 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int coinflip = (int)(Math.random() * 2);
System.out.print("Heads or Tails? ");
String guess = input.next();
if (coinflip == 1) {
System.out.println("Heads");
if (guess.toUpperCase().equals("HEADS")) {
System.out.println("You are correct!");
}
else if (guess.toUpperCase().equals("TAILS")) {
System.out.println("You are incorrect!");
}
else {
System.out.println("Incorrect input");
}
}
else {
System.out.println("Tails");
if (guess.toUpperCase().equals("HEADS")) {
System.out.println("You are incorrect!");
}
else if (guess.toUpperCase().equals("TAILS")) {
System.out.println("You are correct!");
}
else {
System.out.println("Incorrect input");
}
}
}
}