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