Advertisement
veronikaaa86

04. Clever Lily

Nov 21st, 2021
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. package forLoops;
  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 washingMachine = Double.parseDouble(scanner.nextLine());
  11. int toyPrice = Integer.parseInt(scanner.nextLine());
  12.  
  13. int countToys = 0;
  14. int money = 0;
  15. int allMoney = 0;
  16. int brotherCount = 0;
  17. for (int i = 1; i <= age; i++) {
  18. if (i % 2 != 0) {
  19. countToys++;
  20. } else {
  21. money = money + 10 ;
  22. allMoney = allMoney + money;
  23.  
  24. brotherCount++;
  25. }
  26. }
  27.  
  28. int totalSum = allMoney + (countToys * toyPrice) - brotherCount;
  29.  
  30. double diff = Math.abs(totalSum - washingMachine);
  31. if (totalSum >= washingMachine) {
  32. System.out.printf("Yes! %.2f", diff);
  33. } else {
  34. System.out.printf("No! %.2f", diff);
  35. }
  36. }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement