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 lillyAge = Integer.parseInt(scanner.nextLine());
- double washingMachine = Double.parseDouble(scanner.nextLine());
- int toyPrice = Integer.parseInt(scanner.nextLine());
- int evenYears = 0;
- int oddYears = 0;
- int moneyEvenYears = 0;
- // odd years -> toy
- // even years -> money 10lv for first and 10lv more for every next
- //Lilly brother cheat with 1 lv for each money year
- // lilly sll toys for for numberOfToys * toyPrice
- // if enough left = total - washing machine price
- // if not enough = washing machine - total
- for (int years = 1; years <= lillyAge; years++) {
- if (years % 2 == 0) {
- evenYears++;
- moneyEvenYears = (evenYears * 10) + moneyEvenYears;
- } else {
- oddYears++;
- }
- // deduct 1 lv for each even year, brother cheat
- }
- int netMoney = moneyEvenYears - evenYears;
- int moneyFromToys = oddYears * toyPrice;
- int totalSaved = netMoney + moneyFromToys;
- if ( totalSaved> washingMachine){
- double left = totalSaved - washingMachine;
- System.out.printf("Yes! %.2f", left);
- } else {
- double need = washingMachine - totalSaved;
- System.out.printf("No! %.2f", need);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement