Advertisement
veronikaaa86

11. Clever Lily

Mar 27th, 2021
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. package forLoops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P11CleverLily {
  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 countBrother = 0;
  14. int toysCounter = 0;
  15. double sumMoney = 0;
  16. double money = 0;
  17. for (int i = 1; i <= age; i++) {
  18.  
  19. if (i % 2 != 0) {
  20. toysCounter++;
  21. } else {
  22. countBrother++;
  23. money = money + 10;
  24. sumMoney = sumMoney + money;
  25. }
  26. }
  27.  
  28. int allToysMoney = toysCounter * toyPrice;
  29.  
  30. double allMoney = allToysMoney + sumMoney - countBrother;
  31.  
  32. double diff = Math.abs(allMoney - washMachinePrice);
  33. if (allMoney >= washMachinePrice) {
  34. System.out.printf("Yes! %.2f", diff);
  35. } else {
  36. System.out.printf("No! %.2f", diff);
  37. }
  38. }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement