Advertisement
Yargi

GameNumberWars

Sep 11th, 2020
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class NumberWars {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner sc = new Scanner(System.in);
  8.  
  9.         String playerOne = sc.nextLine();
  10.         String playerTwo = sc.nextLine();
  11.  
  12.         int pointsPlayerOne = 0;
  13.         int pointsPlayerTwo = 0;
  14.  
  15.         String input = sc.nextLine();
  16.         while (!"End of game".equals(input)){
  17.  
  18.             int firstCard = Integer.parseInt(input);
  19.             int secondCard = Integer.parseInt(sc.nextLine());
  20.  
  21.  
  22.             if (firstCard > secondCard){
  23.  
  24.                 pointsPlayerOne += firstCard - secondCard;
  25.  
  26.             } else if (firstCard < secondCard){
  27.  
  28.                 pointsPlayerTwo += secondCard - firstCard;
  29.  
  30.             } else {
  31.  
  32.                 while (true){
  33.  
  34.                     firstCard = Integer.parseInt(sc.nextLine());
  35.                     secondCard = Integer.parseInt(sc.nextLine());
  36.  
  37.                     if (firstCard > secondCard){
  38.  
  39.                         System.out.printf("Number wars!%n%s is winner with %d points%n", playerOne, pointsPlayerOne);
  40.                         break;
  41.  
  42.                     } else if (firstCard < secondCard){
  43.  
  44.                         System.out.printf("Number wars!%n%s is winner with %d points%n", playerTwo, pointsPlayerTwo);
  45.                         break;
  46.  
  47.                     }
  48.                 }
  49.                 break;
  50.             }
  51.             input = sc.nextLine();
  52.         }
  53.         if ("End of game".equals(input)){
  54.             System.out.printf("%s has %d points%n%s has %d points%n", playerOne, pointsPlayerOne, playerTwo, pointsPlayerTwo);
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement