Advertisement
veronikaaa86

04. Clever Lily

Jan 30th, 2022
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. package forLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P04CleverLily {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int age = Integer.parseInt(scanner.nextLine());
  10. double washMachinePrice = Double.parseDouble(scanner.nextLine());
  11. int toyPrice = Integer.parseInt(scanner.nextLine());
  12.  
  13. int countToys = 0;
  14. double money = 0;
  15. double allMoney = 0;
  16. int brotherCount = 0;
  17. for (int i = 1; i <= age; i++) {
  18.  
  19. if (i % 2 != 0) {
  20. countToys++;
  21. } else {
  22. brotherCount++;
  23. money = money + 10;
  24. allMoney = allMoney + money;
  25. }
  26. }
  27.  
  28. double sumToys = countToys * toyPrice;
  29. double totalSum = sumToys + allMoney - brotherCount;
  30.  
  31. double diff = Math.abs(totalSum - washMachinePrice);
  32. if (totalSum >= washMachinePrice) {
  33. System.out.printf("Yes! %.2f", diff);
  34. } else {
  35. System.out.printf("No! %.2f", diff);
  36. }
  37. }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement