Advertisement
paykova

SmartLili

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