Advertisement
Spocoman

01. Back To The Past

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