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 initialEnergy = Integer.parseInt(scanner.nextLine());
- String input = scanner.nextLine();
- int countOfBattle = 0;
- int winBattle = 0;
- boolean IsFinish = false;
- while (!input.equals("End of battle")){
- countOfBattle++;
- int distance = Integer.parseInt(input);
- int reducedEnergu = initialEnergy - distance;
- if (reducedEnergu >= 0){
- winBattle++;
- if (countOfBattle % 3 == 0){
- reducedEnergu += countOfBattle;
- }
- initialEnergy = reducedEnergu;
- }else {
- System.out.println(String.format("Not enough energy! Game ends with %d won battles and %d energy",
- winBattle,initialEnergy));
- IsFinish = true;
- }
- input = scanner.nextLine();
- }
- if (!IsFinish){
- System.out.println(String.format("Won battles: %d. Energy left: %d",
- winBattle,initialEnergy));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement