Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Battle {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int countFirstPlayer = Integer.parseInt(scanner.nextLine());
- int countSecondPlayer = Integer.parseInt(scanner.nextLine());
- String winner = scanner.nextLine();
- while (!"End of battle".equals(winner)) {
- if ("one".equals(winner)) {
- countSecondPlayer--;
- }
- if ("two".equals(winner)) {
- countFirstPlayer--;
- }
- int diff = Math.abs(countFirstPlayer - countSecondPlayer);
- if (countFirstPlayer < 0) {
- System.out.printf("Player one is out of eggs. Player two has %d eggs left", diff);
- countFirstPlayer++;
- } else {
- System.out.printf("Player two is out of eggs. Player one has %d eggs left.", diff);
- break;
- }
- winner = scanner.nextLine();
- }
- int diff = Math.abs(countFirstPlayer - countSecondPlayer);
- if("End of battle".equals(winner)){
- System.out.printf("Player one has %d eggs left." , diff );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement