Advertisement
Krassi_Daskalova

Clever Lili

Feb 18th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CleverLili {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int liliAge = Integer.parseInt(scanner.nextLine());
  8. double washerPrice = Double.parseDouble(scanner.nextLine());
  9. int toyPrice = Integer.parseInt(scanner.nextLine());
  10. int savedMoneyFromBd = 0;
  11. int toyNum = 0;
  12. int savedMoneyFromToys = 0;
  13. double totalSavedMoney = 0;
  14. int m = 1;
  15.  
  16. for (int i = 1; i <= liliAge; i++) {
  17.  
  18. if (i % 2 == 0) {
  19. savedMoneyFromBd = savedMoneyFromBd + m * 10;
  20. m++;
  21. } else {
  22. toyNum++;
  23. savedMoneyFromToys = toyNum * toyPrice;
  24. }
  25. totalSavedMoney = savedMoneyFromToys + savedMoneyFromBd - (m-1);
  26. }
  27.  
  28. if (totalSavedMoney > washerPrice) {
  29. System.out.printf("Yes! %.2f", totalSavedMoney - washerPrice);
  30. } else {
  31. System.out.printf("No! %.2f", washerPrice - totalSavedMoney);
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement