Advertisement
veronikaaa86

01. Counter-Strike

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