Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 roundCounter = 0;
- while (!input.equals("End of battle")) {
- int distance = Integer.parseInt(input);
- if (distance <= energy) {
- energy -= distance;
- roundCounter++;
- if (roundCounter % 3 == 0) {
- energy += roundCounter;
- }
- } else {
- System.out.printf("Not enough energy! Game ends with %d won battles and %d energy",
- roundCounter, energy);
- return;
- }
- input = scanner.nextLine();
- }
- System.out.printf("Won battles: %d. Energy left: %d", roundCounter, energy);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment