Advertisement
GabrielHr00

04. Clever Lily

Jun 4th, 2023
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. package S4_FoorLoops;
  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 years = 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 currentMoney = 10;
  15.  
  16.         for (int i = 1; i <= years; i++) {
  17.             if (i % 2 == 0) {
  18.                 savedMoney += currentMoney;
  19.                 currentMoney += 10;
  20.                 savedMoney--;
  21.             } else {
  22.                 toysCount += 1;
  23.             }
  24.         }
  25.  
  26.         int soldToysSum = toyPrice * toysCount;
  27.         savedMoney += soldToysSum;
  28.  
  29.         double diff = Math.abs(washingMachinePrice - savedMoney);
  30.         if(savedMoney >= washingMachinePrice) {
  31.             System.out.printf("Yes! %.2f", diff);
  32.         } else {
  33.             System.out.printf("No! %.2f", diff);
  34.         }
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement