Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class GameNumberWars2 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String namePlayerOne = scanner.nextLine();
- String namePlayerTwo = scanner.nextLine();
- int points1 = 0;
- int points2 = 0;
- boolean numberWars = false;
- String input = scanner.nextLine();
- while (!input.equals("End of game")) {
- int card1 = Integer.parseInt(input);
- int card2 = Integer.parseInt(scanner.nextLine());
- if (numberWars) {
- if (card1 > card2) {
- System.out.println("Number wars!");
- System.out.printf("%s is winner with %d points", namePlayerOne, points1);
- } else {
- System.out.printf("%s is the winner with %d points", namePlayerTwo, points2 );
- }
- break;
- }
- if (card1 == card2) {
- input = scanner.nextLine();
- numberWars = true;
- continue;
- }
- if (card1 > card2) {
- points1 = points1 + (card1 - card2);
- } else {
- points2 = points2 + (card2 - card1);
- }
- input = scanner.nextLine();
- }
- if (!numberWars) {
- System.out.printf("%s has %d points%n", namePlayerOne, points1);
- System.out.printf("%s has %d points", namePlayerTwo, points2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement