Advertisement
Guest User

Untitled

a guest
May 20th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Battle {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int countFirstPlayer = Integer.parseInt(scanner.nextLine());
  8.         int countSecondPlayer = Integer.parseInt(scanner.nextLine());
  9.  
  10.         String winner = scanner.nextLine();
  11.         while (!"End of battle".equals(winner)) {
  12.  
  13.             if ("one".equals(winner)) {
  14.                 countSecondPlayer--;
  15.             }
  16.             if ("two".equals(winner)) {
  17.                 countFirstPlayer--;
  18.             }
  19.             int diff = Math.abs(countFirstPlayer - countSecondPlayer);
  20.             if (countFirstPlayer < 0) {
  21.                 System.out.printf("Player one is out of eggs. Player two has %d eggs left", diff);
  22.                 countFirstPlayer++;
  23.             } else {
  24.                 System.out.printf("Player two is out of eggs. Player one has %d eggs left.", diff);
  25.                 break;
  26.             }
  27.  
  28.             winner = scanner.nextLine();
  29.         }
  30.         int diff = Math.abs(countFirstPlayer - countSecondPlayer);
  31.         if("End of battle".equals(winner)){
  32.             System.out.printf("Player one has %d eggs left." , diff );
  33.  
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement