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