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