Advertisement
GabrielHr00

04. Clever Lily

Mar 31st, 2024
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. package _04_ForLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class CleverLily {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int age = Integer.parseInt(scanner.nextLine());
  9.         double washingMachinePrice = Double.parseDouble(scanner.nextLine());
  10.         int toyPrice = Integer.parseInt(scanner.nextLine());
  11.  
  12.         int toysCount = 0;
  13.         int savedMoney = 0;
  14.         int birthdayMoney = 10;
  15.  
  16.         for (int i = 1; i <= age; i += 1) {
  17.  
  18.             if (i % 2 == 0) {
  19.                 savedMoney += birthdayMoney;
  20.                 birthdayMoney += 10;
  21.  
  22.                 savedMoney--;
  23.                 //savedMoney -= 1;
  24.                 //savedMoney = savedMoney - 1;
  25.             } else {
  26.                 toysCount += 1;
  27.                 // toysCount++;
  28.             }
  29.         }
  30.  
  31.         int toysTotalSum = toyPrice * toysCount;
  32.         savedMoney += toysTotalSum;
  33.  
  34.         if (savedMoney >= washingMachinePrice) {
  35.             System.out.printf("Yes! %.2f", savedMoney - washingMachinePrice);
  36.         } else {
  37.             System.out.printf("No! %.2f", washingMachinePrice - savedMoney);
  38.         }
  39.  
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement