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