Advertisement
veronikaaa86

Smart Lilly

Oct 29th, 2017
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P04_SmartLilly {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int age = Integer.parseInt(scanner.nextLine());
  8.         double priceMachine = Double.parseDouble(scanner.nextLine());
  9.         int priceToy = Integer.parseInt(scanner.nextLine());
  10.  
  11.         double allMoneyEvenYear = 0;
  12.         double allMoneyOddYear = 0;
  13.         double moneyEvenYear = 0;
  14.         double brotherTook = 0;
  15.         for (int i = 1; i <= age; i++) {
  16.  
  17.             if (i % 2 == 0) {
  18.                 moneyEvenYear += 10;
  19.                 allMoneyEvenYear += moneyEvenYear;
  20.                 brotherTook += 1;
  21.             } else {
  22.                 allMoneyOddYear += priceToy;
  23.             }
  24.         }
  25.         double leftMoney = (allMoneyEvenYear - brotherTook) + allMoneyOddYear;
  26.         double diff = Math.abs(priceMachine - leftMoney);
  27.  
  28.         if (leftMoney >= priceMachine) {
  29.             System.out.printf("Yes! %.2f", diff);
  30.         } else {
  31.             System.out.printf("No! %.2f", diff);
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement