Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package S4_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 evenBirthdayMoney = 0;
- int totalSum = 0;
- int toysCount = 0;
- for (int i = 1; i <= age; i++) {
- // check for even birthday
- if(i % 2 == 0) {
- // save all of the money
- // evenBirthdayMoney = evenBirthdayMoney + 10;
- evenBirthdayMoney += 10;
- totalSum += evenBirthdayMoney;
- // brother takes money
- //totalSum = totalSum - 1;
- //totalSum--;
- totalSum -= 1;
- }
- // check for odd birthday
- else {
- toysCount++;
- }
- }
- // add toys sum
- totalSum += toysCount * toyPrice;
- double diff = Math.abs(washingMachinePrice - totalSum);
- if(totalSum >= washingMachinePrice) {
- System.out.printf("Yes! %.2f", diff);
- } else {
- System.out.printf("No! %.2f", diff);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement