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