Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class DemoForBackToThePast {
  4.  
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8.  
  9. double money = Double.parseDouble(scanner.nextLine());
  10. int endYear = Integer.parseInt(scanner.nextLine());
  11.  
  12. int countEvevnYear = 0;
  13. int countOddYear = 0;
  14.  
  15. int ivanchoYear = 17;
  16.  
  17. for (int i = 1800; i <= endYear; i++) {
  18. ivanchoYear++;
  19.  
  20. if (i % 2 != 0) {
  21. countOddYear += 12000 + (ivanchoYear * 50);
  22.  
  23.  
  24. } else {
  25. countEvevnYear += +12000;
  26. }
  27.  
  28.  
  29. }
  30.  
  31. int expense = countEvevnYear + countOddYear;
  32.  
  33. if (money > expense) {
  34.  
  35. System.out.printf("Yes! He will live a carefree life and will have %.2f dollars left.", money - expense);
  36. } else {
  37. System.out.printf("He will need %.2f dollars to survive.", expense - money);
  38. }
  39.  
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement