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