Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class trying {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int initialEnergy = Integer.parseInt(scanner.nextLine());
- int games = 0;
- String commands = scanner.nextLine();
- while (!commands.equals("End of battle")) {
- if (initialEnergy >= Integer.parseInt(commands)) {
- games++;
- initialEnergy -= Integer.parseInt(commands);
- if (games % 3 == 0) {
- initialEnergy += games;
- }
- } else if (initialEnergy < Integer.parseInt(commands)) {
- System.out.printf("Not enough energy! Game ends with %d won battles and %d energy", games, initialEnergy);
- break;
- }
- commands = scanner.nextLine();
- }
- if (commands.equals("End of battle")) {
- System.out.printf("Won battles: %d. Energy left: %d", games, initialEnergy); }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement