Advertisement
Roadstar3

first

Apr 7th, 2020
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class first {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int energy = Integer.parseInt(scanner.nextLine());
  7.         String command = scanner.nextLine();
  8.         int countBattle = 0;
  9.  
  10.         while (!command.equals("End of battle")) {
  11.             int n = Integer.parseInt(command);
  12.             if (energy < n) {
  13.                 System.out.printf("Not enough energy! Game ends with %d won battles and %d energy", countBattle, energy);
  14.                 break;
  15.             }
  16.             countBattle++;
  17.             if (countBattle % 3 == 0) {
  18.                 energy += countBattle;
  19.             }
  20.             energy -= n;
  21.  
  22.             command = scanner.nextLine();
  23.         }
  24.         if (command.equals("End of battle")) {
  25.             System.out.printf("Won battles: %d. Energy left: %d", countBattle, energy);
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement