Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class demo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double moneyNeeded = Double.parseDouble(scanner.nextLine());
- double moneyAvailable = Double.parseDouble(scanner.nextLine());
- int days = 0;
- int daysSpending = 0;
- boolean taqHarchiMn = false;
- while (moneyAvailable < moneyNeeded) {
- String action = scanner.nextLine();
- double amount = Double.parseDouble(scanner.nextLine());
- days++;
- if (action.equals("save")) {
- moneyAvailable += amount;
- daysSpending = 0;
- } else {
- daysSpending++;
- moneyAvailable -= amount;
- if (moneyAvailable <= 0) {
- moneyAvailable = 0;
- }
- if (daysSpending == 5) {
- System.out.printf("You can't save the money.\n" +
- "%d\n", daysSpending);
- taqHarchiMn = true;
- break;
- }
- }
- }
- if (!taqHarchiMn) {
- System.out.printf("You saved the money for %d days.", days);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement