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