Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MidExamPreparatio10February2025;
- import java.util.Scanner;
- public class CounterStrike01 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner (System.in);
- int initialEnergy = Integer.parseInt(scanner.nextLine());
- String input = scanner.nextLine();
- int energy = initialEnergy;
- int wonBattles = 0;
- while (!input.equals("End of battle")){
- if (energy <= 0){
- System.out.printf("Not enough energy! Game ends with %d won battles and 0 energy", wonBattles);
- return;
- }
- int distance = Integer.parseInt(input);
- energy -= distance;
- if (energy > 0){
- wonBattles++;
- if (wonBattles % 3 == 0) {
- energy += wonBattles;
- }
- }
- input = scanner.nextLine();
- }
- //Not enough energy! Game ends with 7 won battles and 0 energy
- if (energy > 0) {
- System.out.printf("Won battles: %d. Energy left: %d", wonBattles, energy);
- }
- }
- }
- ///tmp/ExecutionStrategies/b4kmirye.s2w/tmpe3s3li.tmp:79
- // run: package MidExamPreparatio10February2025;
- // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- //
- //SyntaxError: Unexpected identifier
- // at wrapSafe (internal/modules/cjs/loader.js:915:16)
- // at Module._compile (internal/modules/cjs/loader.js:963:27)
- // at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
- // at Module.load (internal/modules/cjs/loader.js:863:32)
- // at Function.Module._load (internal/modules/cjs/loader.js:708:14)
- // at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
- // at internal/main/run_main_module.js:17:47
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement