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