Advertisement
GabrielHr00

CleverLily

Nov 20th, 2022
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. package S4_ForLoops;
  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 washingMachinePrice = Double.parseDouble(scanner.nextLine());
  10. int toyPrice = Integer.parseInt(scanner.nextLine());
  11.  
  12. int evenBirthdayMoney = 0;
  13. int totalSum = 0;
  14. int toysCount = 0;
  15.  
  16. for (int i = 1; i <= age; i++) {
  17. // check for even birthday
  18. if(i % 2 == 0) {
  19. // save all of the money
  20. // evenBirthdayMoney = evenBirthdayMoney + 10;
  21. evenBirthdayMoney += 10;
  22. totalSum += evenBirthdayMoney;
  23.  
  24. // brother takes money
  25. //totalSum = totalSum - 1;
  26. //totalSum--;
  27. totalSum -= 1;
  28. }
  29. // check for odd birthday
  30. else {
  31. toysCount++;
  32. }
  33. }
  34.  
  35. // add toys sum
  36. totalSum += toysCount * toyPrice;
  37.  
  38. double diff = Math.abs(washingMachinePrice - totalSum);
  39. if(totalSum >= washingMachinePrice) {
  40. System.out.printf("Yes! %.2f", diff);
  41. } else {
  42. System.out.printf("No! %.2f", diff);
  43. }
  44. }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement