Advertisement
YavorGrancharov

BackToThePast

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