Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyClass {
- public static void main(String args[]) {
- java.util.Scanner scanner = new java.util.Scanner(System.in);
- int playerOneNbrEggs = Integer.parseInt(scanner.nextLine());
- int playerTwoNbrEggs = Integer.parseInt(scanner.nextLine());
- String input = "";
- while (playerOneNbrEggs > 0 && playerTwoNbrEggs > 0 && !input.equals("End")) {
- input = scanner.nextLine();
- switch(input) {
- case "one" : playerTwoNbrEggs--; break;
- case "two" : playerOneNbrEggs--; break;
- }
- }
- if (playerOneNbrEggs == 0) {
- System.out.println("Player one is out of eggs.");
- } else {
- System.out.printf("Player one has %d eggs left.\n", playerOneNbrEggs);
- }
- if (playerTwoNbrEggs == 0) {
- System.out.println("Player two is out of eggs.");
- } else {
- System.out.printf("Player two has %d eggs left.", playerTwoNbrEggs);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement