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