Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Demo {
- 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 priceForToy = Integer.parseInt(scanner.nextLine());
- int countBrotherStealing = 0;
- double moneyEveryYear = 0;
- double toyMoney = 0;
- double savedMoney = 0;
- for (int i = 1; i <= age; i++) {
- if (i % 2 == 0) {
- moneyEveryYear += 10;
- countBrotherStealing++;
- savedMoney += moneyEveryYear;
- } else {
- toyMoney += priceForToy;
- }
- }
- savedMoney = savedMoney + toyMoney - countBrotherStealing;
- if (savedMoney > washingMachinePrice) {
- System.out.printf("Yes! %.2f", (savedMoney - washingMachinePrice));
- } else {
- System.out.printf("No! %.2f", (washingMachinePrice - savedMoney));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement