Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class NumberWars {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String playerOne = sc.nextLine();
- String playerTwo = sc.nextLine();
- int pointsPlayerOne = 0;
- int pointsPlayerTwo = 0;
- String input = sc.nextLine();
- while (!"End of game".equals(input)){
- int firstCard = Integer.parseInt(input);
- int secondCard = Integer.parseInt(sc.nextLine());
- if (firstCard > secondCard){
- pointsPlayerOne += firstCard - secondCard;
- } else if (firstCard < secondCard){
- pointsPlayerTwo += secondCard - firstCard;
- } else {
- while (true){
- firstCard = Integer.parseInt(sc.nextLine());
- secondCard = Integer.parseInt(sc.nextLine());
- if (firstCard > secondCard){
- System.out.printf("Number wars!%n%s is winner with %d points%n", playerOne, pointsPlayerOne);
- break;
- } else if (firstCard < secondCard){
- System.out.printf("Number wars!%n%s is winner with %d points%n", playerTwo, pointsPlayerTwo);
- break;
- }
- }
- break;
- }
- input = sc.nextLine();
- }
- if ("End of game".equals(input)){
- System.out.printf("%s has %d points%n%s has %d points%n", playerOne, pointsPlayerOne, playerTwo, pointsPlayerTwo);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement