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