borkins

Exam 17-Jul-2016 - 04. Back to the Past

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