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 moneyNeeded = Double.parseDouble(scanner.nextLine());
- double money = Double.parseDouble(scanner.nextLine());
- int spendDays = 0;
- int days = 0;
- while (money < moneyNeeded) {
- String status = scanner.nextLine();
- double sum = Double.parseDouble(scanner.nextLine());
- if (status.equals("spend")) {
- money -= sum;
- if (money < 0) {
- money = 0;
- }
- spendDays++;
- }else if (status.equals("save")) {
- money += sum;
- spendDays = 0;
- }
- days++;
- if (spendDays == 5) {
- System.out.printf("You can't save the money.%n%d",days);
- break;
- }}
- if (money >= moneyNeeded) {
- System.out.printf("You saved the money for %s days.", days);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement