Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 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.                         wonBattle = 0;
  23.                     }
  24.  
  25.                 }
  26.                 else if (initialEnergy - command1 < 0) {
  27.                     initialEnergy = 0;
  28.                     System.out.printf("Not enough energy! Game ends with %d won battles and %d energy%n", wonBattle, initialEnergy);
  29.  
  30.                 }
  31.  
  32.  
  33.                 command = scanner.nextLine();
  34.             }
  35.  
  36.  
  37.              System.out.printf("Won battles: %d. Energy left: %d", wonBattle, initialEnergy);
  38.  
  39.  
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement