Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class GameNumWar {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String playerOneName = scanner.nextLine();
- String playerTwoName = scanner.nextLine();
- int playerOnePoints = 0;
- int playerTwoPoints = 0;
- while (!playerOneName.equals("End of game")){
- 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 (playerOneName.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