-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCounterStrike.java
More file actions
36 lines (30 loc) · 1.02 KB
/
Copy pathCounterStrike.java
File metadata and controls
36 lines (30 loc) · 1.02 KB
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
package MidExam;
import java.util.Scanner;
public class CounterStrike {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int energy = Integer.parseInt(scanner.nextLine());
String input = scanner.nextLine();
int wonBattle = 0;
boolean lessEnergy = false;
while(!input.equals("End of battle")){
int distance = Integer.parseInt(input);
if(energy >= distance){
wonBattle ++;
energy -= distance;
}else if(energy < distance){
lessEnergy = true;
break;
}
if(wonBattle % 3 == 0){
energy += wonBattle;
}
input = scanner.nextLine();
}
if(lessEnergy){
System.out.printf("Not enough energy! Game ends with %d won battles and %d energy",wonBattle,energy);
}else{
System.out.printf("Won battles: %d. Energy left: %d",wonBattle,energy);
}
}
}