Advertisement
ralitsa_d

SmartLily

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