Advertisement
Dido09

CleverLily

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