Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BackToThePast {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- double heritage = Double.parseDouble(scan.nextLine());
- int yearToLive = Integer.parseInt(scan.nextLine());
- int years = 18;
- for (int currentYear = 1800; currentYear <= yearToLive; currentYear++) {
- if (currentYear % 2 == 0) {
- heritage -= 12000;
- } else heritage -= (12000 + 50 * years);
- years++;
- }
- if (heritage < 0) {
- System.out.printf("He will need %.2f dollars to survive.", Math.abs(heritage));
- } else System.out.printf("Yes! He will live a carefree life and will have %.2f dollars left.", heritage);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement