-
Notifications
You must be signed in to change notification settings - Fork 0
/
Challenge13.java
76 lines (69 loc) · 1.48 KB
/
Challenge13.java
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.util.*;
/**
*
*/
/**
* @author kvito
*
*/
public class Challenge13 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
Random rnd = new Random();
int n = rnd.nextInt(10) + 20;
System.out.println("Starting number: " + n);
while(n > 0){
System.out.print("How many do you want to remove? ");
int player = in.nextInt();
while(player < 1 || player > 3){
System.out.print("Invalid input. How many do you want to remove?");
player = in.nextInt();
}
if(n == 3 && player == 3){
System.out.println("Computer wins");
break;
}
else if (n == 2 && player == 2){
System.out.println("Computer wins");
break;
}
else if (n == 1 && player == 1){
System.out.println("Computer wins");
break;
}
n -= player;
System.out.println(n + " left");
int comp = 0;
if(n == 1){
System.out.println("You win");
break;
}
else if (n == 2){
n -= 1;
System.out.println("Computer removes 1");
System.out.println(n + " left");
}
else if(n == 3){
n -= 2;
System.out.println("Computer removes 2");
System.out.println(n + " left");
}
else if (n > 3){
comp = rnd.nextInt(3) + 1;
System.out.println("Computer removes " + comp);
if((n -= comp) > 0){
System.out.println(n + " left");
}
else {
System.out.println("You win");
break;
}
}
}
in.close();
}
}