Advertisement
psi_mmobile

Untitled

Oct 21st, 2022
1,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. public class MyClass {
  2.     public static void main(String args[]) {
  3.         java.util.Scanner scanner = new java.util.Scanner(System.in);
  4.         int energy = Integer.valueOf(scanner.nextLine());
  5.         String nextCommand = null;
  6.         int battlesWon = 0;
  7.         int distance = 0;
  8.         while(true) {
  9.             nextCommand = scanner.nextLine();
  10.             if (nextCommand.equals("End of battle")) {
  11.                 System.out.printf("Won battles: %d. Energy left: %d", battlesWon, energy);
  12.                 break;
  13.             } else {
  14.                 distance = Integer.valueOf(nextCommand);
  15.                 if (energy >= distance) {
  16.                     energy -= distance;
  17.                     battlesWon++;
  18.                     if (battlesWon % 3 == 0) {
  19.                         energy += battlesWon;
  20.                     }
  21.                 } else {
  22.                     System.out.printf("Not enough energy! Game ends with %d won battles and %d energy", battlesWon, energy);
  23.                     break;
  24.                 }
  25.             }
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement