ralitsa_d

BackToThePast

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