Advertisement
Spocoman

Game Number Wars

Sep 7th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String player1 = scanner.nextLine(),
  7.                 player2 = scanner.nextLine(),
  8.                 command;
  9.  
  10.         int card1, card2, point1 = 0, point2 = 0;
  11.  
  12.         while (!(command = scanner.nextLine()).equals("End of game")) {
  13.             card1 = Integer.parseInt(command);
  14.             card2 = Integer.parseInt(scanner.nextLine());
  15.  
  16.             if (card1 > card2) {
  17.                 point1 += card1 - card2;
  18.             } else if (card1 < card2) {
  19.                 point2 += card2 - card1;
  20.             } else {
  21.                 card1 = Integer.parseInt(scanner.nextLine());
  22.                 card2 = Integer.parseInt(scanner.nextLine());
  23.  
  24.                 System.out.println("Number wars!");
  25.  
  26.                 if (card1 > card2) {
  27.                     System.out.println(player1 + " is winner with " + point1 + " points");
  28.                 } else {
  29.                     System.out.println(player2 + " is winner with " + point2 + " points");
  30.                 }
  31.                 break;
  32.             }
  33.         }
  34.  
  35.         if (command.equals("End of game")) {
  36.             System.out.println(player1 + " has " + point1 + " points\n" + player2 + " has " + point2 + " points");
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement