Advertisement
yovkovbpfps

For Loop CLEVER LILY

Apr 8th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 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 washingMachine = Double.parseDouble(scanner.nextLine());
  9. int toyPrice = Integer.parseInt(scanner.nextLine());
  10.  
  11. int savedMoney = 0;
  12. int toysCount = 0;
  13. for (int y = 1; y <= age; y++) {
  14. if (y % 2 == 0) {
  15. savedMoney += y * 5;
  16. savedMoney--;
  17. } else {
  18. toysCount++;
  19. }
  20. }
  21.  
  22. int totalSum = toyPrice * toysCount + savedMoney;
  23.  
  24. if (totalSum >= washingMachine) {
  25. System.out.printf("Yes! %.2f", totalSum - washingMachine);
  26. } else {
  27. System.out.printf("No! %.2f", washingMachine - totalSum);
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement