Advertisement
Guest User

cs

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