Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package S4_FoorLoops;
- import java.util.Scanner;
- public class CleverLily {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int years = Integer.parseInt(scanner.nextLine());
- double washingMachinePrice = Double.parseDouble(scanner.nextLine());
- int toyPrice = Integer.parseInt(scanner.nextLine());
- int toysCount = 0;
- int savedMoney = 0;
- int currentMoney = 10;
- for (int i = 1; i <= years; i++) {
- if (i % 2 == 0) {
- savedMoney += currentMoney;
- currentMoney += 10;
- savedMoney--;
- } else {
- toysCount += 1;
- }
- }
- int soldToysSum = toyPrice * toysCount;
- savedMoney += soldToysSum;
- double diff = Math.abs(washingMachinePrice - savedMoney);
- if(savedMoney >= washingMachinePrice) {
- System.out.printf("Yes! %.2f", diff);
- } else {
- System.out.printf("No! %.2f", diff);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement