Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Demo {
  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 priceForToy = Integer.parseInt(scanner.nextLine());
  10.  
  11. int countBrotherStealing = 0;
  12. double moneyEveryYear = 0;
  13. double toyMoney = 0;
  14. double savedMoney = 0;
  15. for (int i = 1; i <= age; i++) {
  16.  
  17. if (i % 2 == 0) {
  18. moneyEveryYear += 10;
  19. countBrotherStealing++;
  20. savedMoney += moneyEveryYear;
  21. } else {
  22. toyMoney += priceForToy;
  23. }
  24. }
  25. savedMoney = savedMoney + toyMoney - countBrotherStealing;
  26.  
  27. if (savedMoney > washingMachinePrice) {
  28. System.out.printf("Yes! %.2f", (savedMoney - washingMachinePrice));
  29. } else {
  30. System.out.printf("No! %.2f", (washingMachinePrice - savedMoney));
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement