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