Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SmartLilly {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter Lilly's age: ");
- int age = Integer.parseInt(sc.nextLine());
- System.out.print("Enter the price of the washing machine: ");
- double priceOfWashingMachine = Double.parseDouble(sc.nextLine());
- System.out.print("Enter the price for toys: ");
- int presentPrice = Integer.parseInt(sc.nextLine());
- int numberOfToys = 0;
- int savedMoney = 0;
- int moneyForBirthday = 10;
- for (int currentYear = 1; currentYear <= age; currentYear++) {
- if (currentYear % 2 == 0) {
- savedMoney += (moneyForBirthday - 1);
- moneyForBirthday += 10;
- } else {
- numberOfToys++;
- }
- }
- savedMoney += numberOfToys * presentPrice;
- System.out.println((savedMoney >= priceOfWashingMachine) ?
- String.format("Yes! %.2f", (savedMoney - priceOfWashingMachine))
- : String.format("No! %.2f", (priceOfWashingMachine - savedMoney)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment