-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCleverLily.java
More file actions
39 lines (29 loc) · 1.01 KB
/
Copy pathCleverLily.java
File metadata and controls
39 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package ForLoop;
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 priceWashingMachine = Double.parseDouble(scanner.nextLine());
int toyPrice = Integer.parseInt(scanner.nextLine());
int toysCounter = 0;
int brother = 0;
double money = 0;
double totalMoney = 0;
for (int i = 1; i <= age ; i++) {
if (i % 2 == 0){
money += 10;
totalMoney += money;
brother++;
}else {
toysCounter ++;
}
}
double moneySaved = (totalMoney - brother) + toysCounter * toyPrice;
if(moneySaved >= priceWashingMachine){
System.out.printf("Yes! %.2f",moneySaved - priceWashingMachine);
}else {
System.out.printf("No! %.2f",priceWashingMachine - moneySaved);
}
}
}