Advertisement
Guest User

Game Number wars

a guest
Sep 3rd, 2020
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ExamGameNumberWars2 {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String namePlayerOne = scanner.nextLine();
  8. String namePlayerTwo = scanner.nextLine();
  9. int points1 = 0;
  10. int points2 = 0;
  11.  
  12. String input = scanner.nextLine();
  13. while (!input.equals("End of game")) {
  14. int card1 = Integer.parseInt(input);
  15. int card2 = Integer.parseInt(scanner.nextLine());
  16.  
  17.  
  18. if (card1 > card2) {
  19. points1 = points1 + (card1 - card2);
  20. } else if (card2 > card1) {
  21. points2 = points2 + (card2 - card1);
  22. } else {
  23. System.out.println("Number wars!");
  24. card1 = Integer.parseInt(scanner.nextLine());
  25. card2 = Integer.parseInt(scanner.nextLine());
  26. if (card1 > card2) {
  27. System.out.printf("%s is winner with %d points", namePlayerOne, points1);
  28. break;
  29. } else if (card2 > card1) {
  30. System.out.printf("%s is the winner with %d points", namePlayerTwo, points2);
  31. break;
  32. }
  33. }
  34. input = scanner.nextLine();
  35. }
  36. if (input.equals("End of game")) {
  37.  
  38. System.out.printf("%s has %d points%n", namePlayerOne, points1);
  39. System.out.printf("%s has %d points", namePlayerTwo, points2);
  40. }
  41.  
  42. }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement