Advertisement
Dido09

BackToThePast

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