Advertisement
Lyubohd

Back To The Past

Apr 8th, 2020
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class BackToThePast {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         double inheritedMoney = Double.parseDouble(scan.nextLine());
  8.         int year = Integer.parseInt(scan.nextLine());
  9.         int age = 18;
  10.         int moneyForYear = 12000;
  11.         int moneyInOddYear = 0;
  12.  
  13.         for (int i = 1800; i <= year; i++) {
  14.             if (i % 2 == 0) {
  15.                 inheritedMoney = inheritedMoney - moneyForYear;
  16.             } else {
  17.                 moneyInOddYear = moneyForYear + age * 50;
  18.                 inheritedMoney = inheritedMoney - moneyInOddYear;
  19.             }
  20.             age++;
  21.         }
  22.        
  23.         if (inheritedMoney < 0) {
  24.             System.out.printf("He will need %.2f dollars to survive.%n", Math.abs(inheritedMoney));
  25.         } else {
  26.             System.out.printf("Yes! He will live a carefree life and will have %.2f dollars left.%n", inheritedMoney);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement