Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package _04_ForLoops;
- 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 washingMachinePrice = Double.parseDouble(scanner.nextLine());
- int toyPrice = Integer.parseInt(scanner.nextLine());
- int toysCount = 0;
- int savedMoney = 0;
- int birthdayMoney = 10;
- for (int i = 1; i <= age; i += 1) {
- if (i % 2 == 0) {
- savedMoney += birthdayMoney;
- birthdayMoney += 10;
- savedMoney--;
- //savedMoney -= 1;
- //savedMoney = savedMoney - 1;
- } else {
- toysCount += 1;
- // toysCount++;
- }
- }
- int toysTotalSum = toyPrice * toysCount;
- savedMoney += toysTotalSum;
- 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