Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int firstPlayer = Integer.parseInt(scanner.nextLine()),
- secondPlayer = Integer.parseInt(scanner.nextLine());
- String command;
- while (true) {
- command = scanner.nextLine();
- if (command.equals("End")) {
- System.out.println("Player one has " + firstPlayer + " eggs left.\n"
- + "Player two has " + secondPlayer + " eggs left.");
- break;
- } else if (command.equals("one")) {
- secondPlayer--;
- if (secondPlayer == 0) {
- System.out.println("Player two is out of eggs. Player one has " + firstPlayer + " eggs left.");
- break;
- }
- } else if (command.equals("two")) {
- firstPlayer--;
- if (firstPlayer == 0) {
- System.out.println("Player one is out of eggs. Player two has " + secondPlayer + " eggs left.");
- break;
- }
- }
- }
- }
- }
- ИЛИ:
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int firstPlayer = Integer.parseInt(scanner.nextLine()),
- secondPlayer = Integer.parseInt(scanner.nextLine());
- String command;
- label:
- while (true) {
- command = scanner.nextLine();
- switch (command) {
- case "End":
- System.out.println("Player one has " + firstPlayer + " eggs left.\n"
- + "Player two has " + secondPlayer + " eggs left.");
- break label;
- case "one":
- secondPlayer--;
- if (secondPlayer == 0) {
- System.out.println("Player two is out of eggs. Player one has " + firstPlayer + " eggs left.");
- break label;
- }
- break;
- case "two":
- firstPlayer--;
- if (firstPlayer == 0) {
- System.out.println("Player one is out of eggs. Player two has " + secondPlayer + " eggs left.");
- break label;
- }
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement