yovkovbpfps

EXAM 20 - 21 APRIL Easter Egg Battle

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