Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         long initialEnergy = (long)Integer.parseInt(scanner.nextLine());
  9.         String command = scanner.nextLine();
  10.         long wonBattle = 0;
  11.         boolean win = false;
  12.  
  13.         while (!"End of battle".equals(command)) {
  14.  
  15.                 int command1 = Integer.parseInt(command);
  16.  
  17.                 if (initialEnergy>0 && initialEnergy <= 10000 && initialEnergy <=10000) {
  18.                     initialEnergy = initialEnergy - command1;
  19.                     wonBattle++;
  20.                     if (wonBattle % 3 == 0) {
  21.                         initialEnergy = initialEnergy + wonBattle;
  22.                     }
  23.  
  24.                 }
  25.                 else if (initialEnergy - command1 < 0) {
  26.                     initialEnergy = 0;
  27.                     System.out.printf("Not enough energy! Game ends with %d won battles and %d energy", wonBattle, initialEnergy);
  28.                     win = true;
  29.                     break;
  30.                    
  31.  
  32.                 }
  33.  
  34.  
  35.                 command = scanner.nextLine();
  36.             }
  37.  
  38.  
  39.             if (win== false){
  40.              System.out.printf("Won battles: %d. Energy left: %d", wonBattle, initialEnergy);
  41.             }
  42.  
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement