Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class CleverLily {
- 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 singleToyPrice = Integer.parseInt(scanner.nextLine());
- int toysCount = 0;
- int moneyGiven = 10;
- int savings = 0;
- for (int birthday = 1; birthday <= age; birthday++) {
- if (birthday % 2 == 1) {
- toysCount++;
- } else {
- savings += moneyGiven;
- moneyGiven += 10;
- savings -= 1; // savings = savings - 1
- }
- }
- int profitFromToys = toysCount * singleToyPrice;
- savings += profitFromToys;
- if (savings >= washingMachinePrice) {
- System.out.printf("Yes! %.2f", savings - washingMachinePrice);
- } else {
- System.out.printf("No! %.2f", washingMachinePrice - savings);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement