Advertisement
SvetlozarDragnev

Untitled

Feb 10th, 2025
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.81 KB | None | 0 0
  1. package MidExamPreparatio10February2025;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class CounterStrike01 {
  6.     public static void main(String[] args) {
  7.  
  8.         Scanner scanner = new Scanner (System.in);
  9.  
  10.         int initialEnergy = Integer.parseInt(scanner.nextLine());
  11.         String input = scanner.nextLine();
  12.         int energy = initialEnergy;
  13.         int wonBattles = 0;
  14.  
  15.         while (!input.equals("End of battle")){
  16.  
  17.             if (energy <= 0){
  18.                 System.out.printf("Not enough energy! Game ends with %d won battles and 0 energy", wonBattles);
  19.                 return;
  20.  
  21.             }
  22.  
  23.             int distance = Integer.parseInt(input);
  24.  
  25.             energy -= distance;
  26.  
  27.             if (energy > 0){
  28.                 wonBattles++;
  29.                 if (wonBattles % 3 == 0) {
  30.                     energy += wonBattles;
  31.                 }
  32.             }
  33.  
  34.  
  35.  
  36.             input = scanner.nextLine();
  37.  
  38.  
  39.         }
  40. //Not enough energy! Game ends with 7 won battles and 0 energy
  41.  
  42.         if (energy > 0) {
  43.             System.out.printf("Won battles: %d. Energy left: %d", wonBattles, energy);
  44.         }
  45.  
  46.  
  47.     }
  48. }
  49.  
  50.  
  51.  
  52. ///tmp/ExecutionStrategies/b4kmirye.s2w/tmpe3s3li.tmp:79
  53. //    run: package MidExamPreparatio10February2025;
  54. //                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  55. //
  56. //SyntaxError: Unexpected identifier
  57. //    at wrapSafe (internal/modules/cjs/loader.js:915:16)
  58. //    at Module._compile (internal/modules/cjs/loader.js:963:27)
  59. //    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
  60. //    at Module.load (internal/modules/cjs/loader.js:863:32)
  61. //    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
  62. //    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
  63. //    at internal/main/run_main_module.js:17:47
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement