Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class P09cleverLily {
- 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());
- double moneyGift = 10;
- int toysCount = 0;
- double saving = 0;
- for (int year = 1; year <= age; age++) {
- if (year % 2 == 0) {
- saving += moneyGift - 1;
- moneyGift += 10;
- } else {
- toysCount++;
- }
- }
- int toysPrice = toyPrice * toysCount;
- saving += toyPrice;
- double diff = saving - washingMachinePrice;
- if (diff <= 0) {
- System.out.printf("No! %.2f", Math.abs(diff));
- } else {
- System.out.printf("Yes! %.2f", diff);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment