Advertisement
MladenKarachanov

CleverLily

Sep 28th, 2023
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. package firstStepsInCoding.MoreExercises;
  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 price = Double.parseDouble(scanner.nextLine());
  10.         int onePriceToys = Integer.parseInt(scanner.nextLine());
  11.         int money = 0;
  12.         int toys = 0;
  13.         double allMoney = 0;
  14.         int brotherSum = 0;
  15.         for (int i = 1; i <= age; i++) {
  16.  
  17.             if (i % 2 == 0) {
  18.                 money = money + 10;
  19.                 allMoney = allMoney + money;
  20.                 brotherSum++;
  21.  
  22.             } else {
  23.                 toys++;
  24.             }
  25.         }
  26.             double totalSum = toys * onePriceToys;
  27.             double finish = allMoney + totalSum - brotherSum;
  28.             double diff = Math.abs(finish - price);
  29.             if (finish >= price) {
  30.                 System.out.printf("Yes! %.2f", diff);
  31.             } else {
  32.                 System.out.printf("No! %.2f", diff);
  33.             }
  34.         }
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement