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