Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package forLoop;
- import java.util.Scanner;
- public class P11CleverLily {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int age = Integer.parseInt(scanner.nextLine());
- double washMachinePrice = Double.parseDouble(scanner.nextLine());
- int toyPrice = Integer.parseInt(scanner.nextLine());
- int countToys = 0;
- int brotherCount = 0;
- double currentMoney = 0;
- double sumMoney = 0;
- for (int i = 1; i <= age; i++) {
- if (i % 2 != 0) {
- countToys++;
- } else {
- brotherCount++;
- currentMoney = currentMoney + 10;
- sumMoney = sumMoney + currentMoney;
- }
- }
- double allSavedMoney = (countToys * toyPrice) + (sumMoney - brotherCount);
- double diff = Math.abs(allSavedMoney - washMachinePrice);
- if (allSavedMoney >= washMachinePrice) {
- System.out.printf("Yes! %.2f", diff);
- } else {
- System.out.printf("No! %.2f", diff);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement