Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Vacation {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double moneyNeededForExcursion = Double.parseDouble(scanner.nextLine());
- double moneyHave = Double.parseDouble(scanner.nextLine());
- int countSpendDays = 0;
- int countDays = 0;
- while (!(moneyNeededForExcursion <= moneyHave)) {
- String input = scanner.nextLine();
- double money = Double.parseDouble(scanner.nextLine());
- countDays++;
- if (input.equals("save")) {
- moneyHave += money;
- countSpendDays = 0;
- }else if (input.equals("spend")) {
- countSpendDays++;
- if (moneyHave < money) {
- moneyHave = 0;
- }else {
- moneyHave -= money;
- }
- }
- }
- if (moneyHave >= moneyNeededForExcursion) {
- System.out.printf("You saved the money for %d days.",countDays);
- }else if (countSpendDays >= 5) {
- System.out.printf("You can't save the money.%n%d", countDays);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement