Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CounerStrike {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         int initialEnergy = Integer.parseInt(scan.nextLine());
  8.         int wonBattleCount = 0;
  9.  
  10.         String command = scan.nextLine();
  11.         while (!command.equals("End of battle")) {
  12.             int distanceNeed = Integer.parseInt(command);
  13.  
  14.             if (distanceNeed > initialEnergy) {
  15.                 System.out.printf("Not enough energy! Game ends with %d won battles and %d energy%n"
  16.                         , wonBattleCount, initialEnergy);
  17.                 return;
  18.             } else {
  19.                 initialEnergy = initialEnergy - distanceNeed;
  20.                 wonBattleCount++;
  21.                 if (wonBattleCount % 3 ==0) {
  22.                     initialEnergy += wonBattleCount;
  23.                 }
  24.  
  25.             }
  26.             command = scan.nextLine();
  27.         }
  28.         System.out.printf("Won battles: %d. Energy left: %d", wonBattleCount, initialEnergy);
  29.  
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement