Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Demo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String playerOneName = scanner.nextLine();
- String playerTwoName = scanner.nextLine();
- String command = "";
- int playerOnePoints = 0;
- int playerTwoPoints = 0;
- while (true) {
- command = scanner.nextLine();
- int cardPlayerOne = Integer.parseInt(scanner.nextLine());
- int cardPlayerTwo = Integer.parseInt(scanner.nextLine());
- if (cardPlayerOne > cardPlayerTwo) {
- int diffOne = cardPlayerOne - cardPlayerTwo;
- playerOnePoints += diffOne;
- } else if (cardPlayerTwo > cardPlayerOne) {
- int diffTwo = cardPlayerTwo - cardPlayerOne;
- playerTwoPoints += diffTwo;
- } else {
- cardPlayerOne = Integer.parseInt(scanner.nextLine());
- cardPlayerTwo = Integer.parseInt(scanner.nextLine());
- if (cardPlayerOne > cardPlayerTwo) {
- int diffOne = cardPlayerOne - cardPlayerTwo;
- System.out.println("Number wars!");
- System.out.printf("%s is winner with %d points", playerOneName, playerOnePoints);
- break;
- } else {
- int diffTwo = cardPlayerTwo - cardPlayerOne;
- System.out.println("Number wars!");
- System.out.printf("%s is winner with %d points", playerTwoName, playerTwoPoints);
- break;
- }
- }
- }
- if (command.equals("End of game")) {
- System.out.printf("%s has %d points%n", playerOneName, playerOnePoints);
- System.out.printf("%s has %d points", playerTwoName, playerTwoPoints);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement