Advertisement
Guest User

reshenieBogdan

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