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