Advertisement
bobo_bobkata

Untitled

Sep 24th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class demo {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         double moneyNeeded = Double.parseDouble(scanner.nextLine());
  9.         double moneyAvailable = Double.parseDouble(scanner.nextLine());
  10.         int days = 0;
  11.         int daysSpending = 0;
  12.         boolean taqHarchiMn = false;
  13.  
  14.         while (moneyAvailable < moneyNeeded) {
  15.             String action = scanner.nextLine();
  16.             double amount = Double.parseDouble(scanner.nextLine());
  17.             days++;
  18.             if (action.equals("save")) {
  19.                 moneyAvailable += amount;
  20.                 daysSpending = 0;
  21.             } else {
  22.                 daysSpending++;
  23.                 moneyAvailable -= amount;
  24.                 if (moneyAvailable <= 0) {
  25.                     moneyAvailable = 0;
  26.                 }
  27.  
  28.                 if (daysSpending == 5) {
  29.                     System.out.printf("You can't save the money.\n" +
  30.                             "%d\n", daysSpending);
  31.                     taqHarchiMn = true;
  32.                     break;
  33.                 }
  34.             }
  35.         }
  36.         if (!taqHarchiMn) {
  37.             System.out.printf("You saved the money for %d days.", days);
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement