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