Advertisement
veronikaaa86

04. Easter Eggs Battle

Nov 13th, 2021
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. package examPrep;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P05EasterEggsBattle {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int firstPlayerEggs = Integer.parseInt(scanner.nextLine());
  10. int secondPlayerEggs = Integer.parseInt(scanner.nextLine());
  11.  
  12. String input = scanner.nextLine();//one
  13. while (!input.equals("End of battle")) {
  14. if (input.equals("one")) {
  15. secondPlayerEggs--;
  16. } else if (input.equals("two")) {
  17. firstPlayerEggs--;
  18. }
  19.  
  20. if (firstPlayerEggs == 0 || secondPlayerEggs == 0) {
  21. break;
  22. }
  23.  
  24. input = scanner.nextLine();
  25. }
  26.  
  27. if (firstPlayerEggs == 0) {
  28. System.out.printf("Player one is out of eggs. Player two has %d eggs left.", secondPlayerEggs);
  29. } else if (secondPlayerEggs == 0) {
  30. System.out.printf("Player two is out of eggs. Player one has %d eggs left.", firstPlayerEggs);
  31. } else {
  32. System.out.printf("Player one has %d eggs left.%n", firstPlayerEggs);
  33. System.out.printf("Player two has %d eggs left.%n", secondPlayerEggs);
  34. }
  35. }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement