galinyotsev123

ProgBasics06For-Loop-P09cleverLily*

Jan 5th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P09cleverLily {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int age = Integer.parseInt(scanner.nextLine());
  8. double washingMachinePrice = Double.parseDouble(scanner.nextLine());
  9. int toyPrice = Integer.parseInt(scanner.nextLine());
  10.  
  11. double moneyGift = 10;
  12. int toysCount = 0;
  13. double saving = 0;
  14.  
  15. for (int year = 1; year <= age; age++) {
  16. if (year % 2 == 0) {
  17. saving += moneyGift - 1;
  18. moneyGift += 10;
  19. } else {
  20. toysCount++;
  21. }
  22. }
  23. int toysPrice = toyPrice * toysCount;
  24. saving += toyPrice;
  25.  
  26. double diff = saving - washingMachinePrice;
  27. if (diff <= 0) {
  28. System.out.printf("No! %.2f", Math.abs(diff));
  29. } else {
  30. System.out.printf("Yes! %.2f", diff);
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment