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