Advertisement
Guest User

Untitled

a guest
Aug 31st, 2019
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class GameNumWar {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String playerOneName = scanner.nextLine();
  8.         String playerTwoName = scanner.nextLine();
  9.  
  10.         int playerOnePoints = 0;
  11.         int playerTwoPoints = 0;
  12.  
  13.  
  14.         while (!playerOneName.equals("End of game")){
  15.  
  16.             int cardPlayerOne = Integer.parseInt(scanner.nextLine());
  17.             int cardPlayerTwo = Integer.parseInt(scanner.nextLine());
  18.  
  19.             if (cardPlayerOne > cardPlayerTwo) {
  20.                 int diffOne = cardPlayerOne - cardPlayerTwo;
  21.                 playerOnePoints += diffOne;
  22.             } else if (cardPlayerTwo > cardPlayerOne) {
  23.                 int diffTwo = cardPlayerTwo - cardPlayerOne;
  24.                 playerTwoPoints += diffTwo;
  25.             }else {
  26.                 cardPlayerOne = Integer.parseInt(scanner.nextLine());
  27.                 cardPlayerTwo = Integer.parseInt(scanner.nextLine());
  28.                 if (cardPlayerOne > cardPlayerTwo) {
  29.                     int diffOne = cardPlayerOne - cardPlayerTwo;
  30.                     System.out.println("Number wars!");
  31.                     System.out.printf("%s is winner with %d points",playerOneName,playerOnePoints);
  32.                     break;
  33.                 }else {
  34.                     int diffTwo = cardPlayerTwo - cardPlayerOne;
  35.                     System.out.println("Number wars!");
  36.                     System.out.printf("%s is winner with %d points",playerTwoName,playerTwoPoints);
  37.                     break;
  38.                 }
  39.             }
  40.         }
  41.         if (playerOneName.equals("End of game")){
  42.             System.out.printf("%s has %d points%n",playerOneName,playerOnePoints);
  43.             System.out.printf("%s has %d points",playerTwoName,playerTwoPoints);
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement