Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 washPrice = Double.parseDouble(scanner.nextLine());
- double toyPrice = Double.parseDouble(scanner.nextLine());
- int savings = 0;
- int toyCount = 0;
- int brotherShare = 0;
- for (int year = 1; year <= age; year++) {
- if (year % 2 == 0) { // money
- savings += year *10 / 2;
- brotherShare++;
- } else { // toy
- toyCount++;
- }
- }
- // add toys money to savings:
- savings += toyCount * toyPrice;
- // -1 lv. for brother:
- savings -= brotherShare;
- double diff = savings - washPrice;
- if (diff >= 0) {
- System.out.printf("Yes! %.2f",(diff));
- } else {
- System.out.printf("No! %.2f", Math.abs(diff));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement