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 wmoney = Double.parseDouble(scanner.nextLine());
- double gotm = Double.parseDouble(scanner.nextLine());
- int dayspend = 0;
- int days = 0;
- while (dayspend < 5 && gotm < wmoney) {
- String typo = scanner.nextLine();
- double s = Double.parseDouble(scanner.nextLine());
- days += 1;
- if (typo.equals("spend")) {
- dayspend += 1;
- gotm -= s;
- if (dayspend == 5) {
- break;
- }
- if (gotm < 0) {
- gotm = 0;
- }
- } else if (typo.equals("save")) {
- dayspend = 0;
- gotm += s;
- if (gotm >= wmoney) {
- break;
- }
- }
- // typo = scanner.nextLine();
- // s = Integer.parseInt(scanner.nextLine());
- }
- if (gotm >= wmoney) {
- System.out.printf("You saved the money for %d days.", days);
- } else if (dayspend >= 5) {
- System.out.printf("You can't save the money.\n%d", days);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement