Advertisement
Deiancom

Back to the past

Feb 8th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. public class BackToThePast {
  2.     public static void main(String[] args) {
  3.         Scanner scanner = new Scanner(System.in);
  4.         double heritage = Double.parseDouble(scanner.nextLine());
  5.         int ageToLiveIn = Integer.parseInt(scanner.nextLine());
  6.         double moneyLeft = 0;
  7.         int yearsCount = 18;
  8.         for (int i = 1800; i <= ageToLiveIn ; i++) {
  9.             if (i % 2 == 0) {
  10.                 heritage -= 12000;
  11.             }else {
  12.                 heritage -= 12000 + (yearsCount * 50);
  13.             }
  14.             yearsCount++;
  15.         }
  16.         if (heritage >= 0) {
  17.             System.out.printf("Yes! He will live a carefree life and will have %.2f dollars left.",heritage);
  18.         }else {
  19.             System.out.printf("He will need %.2f dollars to survive.",Math.abs(heritage));
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement