Advertisement
zlatinnn

03. Vacation

Jul 7th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class opit {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. double moneyN = Double.parseDouble(scanner.nextLine());
  8. double money = Double.parseDouble(scanner.nextLine());
  9.  
  10. int n = 0;
  11. int n1 = 0;
  12.  
  13. while (!(money > moneyN)) {
  14. String input = scanner.nextLine();
  15. double sum1 = Double.parseDouble(scanner.nextLine());
  16. n++;
  17. if ("save".equals(input)) {
  18. money += sum1;
  19. n1 = 0;
  20. if (money >= moneyN) {
  21. System.out.printf("You saved the money for %d days.", n);
  22. return;
  23. }
  24.  
  25. } else if ("spend".equals(input)) {
  26. n1++;
  27. if (money < sum1) {
  28. money = 0;
  29. } else {
  30. money -= sum1;
  31. }
  32.  
  33. if (n1 >= 5) {
  34. System.out.printf("You can't save the money.%n%d", n);
  35. return;
  36.  
  37. }
  38.  
  39. }
  40. }
  41.  
  42. if (money >= moneyN) {
  43. System.out.printf(" You saved the money for %d days.", n);
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement