Advertisement
veronikaaa86

11. Clever Lily

Jul 24th, 2021
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. package forLoop;
  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 countToys = 0;
  14. int brotherCount = 0;
  15. double currentMoney = 0;
  16. double sumMoney = 0;
  17. for (int i = 1; i <= age; i++) {
  18. if (i % 2 != 0) {
  19. countToys++;
  20. } else {
  21. brotherCount++;
  22. currentMoney = currentMoney + 10;
  23. sumMoney = sumMoney + currentMoney;
  24. }
  25. }
  26.  
  27. double allSavedMoney = (countToys * toyPrice) + (sumMoney - brotherCount);
  28.  
  29. double diff = Math.abs(allSavedMoney - washMachinePrice);
  30. if (allSavedMoney >= washMachinePrice) {
  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