Advertisement
psi_mmobile

Untitled

May 28th, 2022
953
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. public class MyClass {
  2.     public static void main(String args[]) {
  3.         java.util.Scanner scanner = new java.util.Scanner(System.in);
  4.         int playerOneNbrEggs = Integer.parseInt(scanner.nextLine());
  5.         int playerTwoNbrEggs = Integer.parseInt(scanner.nextLine());
  6.         String input = "";
  7.         while (playerOneNbrEggs > 0 && playerTwoNbrEggs > 0 && !input.equals("End")) {
  8.             input = scanner.nextLine();
  9.             switch(input) {
  10.                 case "one" : playerTwoNbrEggs--; break;
  11.                 case "two" : playerOneNbrEggs--; break;
  12.             }
  13.         }
  14.         if (playerOneNbrEggs == 0) {
  15.             System.out.println("Player one is out of eggs.");
  16.         } else {
  17.             System.out.printf("Player one has %d eggs left.\n", playerOneNbrEggs);
  18.         }
  19.         if (playerTwoNbrEggs == 0) {
  20.             System.out.println("Player two is out of eggs.");
  21.         } else {
  22.             System.out.printf("Player two has %d eggs left.", playerTwoNbrEggs);
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement