Advertisement
16112

4.4 Завръщане в миналото

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