retire or not retire ? is a question.

时间:2024-11-17 17:06:49

corejava 上的一段代码 因吹思婷

"C:\Program Files\Java\jdk1.8.0_101\bin\java" -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_101\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_101\jre\lib\rt.jar;D:\MyTest\out\production\MyTest;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain MyTest
How much money will you contribute every year
2700
Internet rate in %:
0.1
After year 1,your balance is 2,702.70
Ready to retire?(Y/N)N
After year 2,your balance is 5,408.10
Ready to retire?(Y/N)N
After year 3,your balance is 8,116.21
Ready to retire?(Y/N)N
After year 4,your balance is 10,827.03
Ready to retire?(Y/N)N
After year 5,your balance is 13,540.55
Ready to retire?(Y/N)N
After year 6,your balance is 16,256.79
Ready to retire?(Y/N)N
After year 7,your balance is 18,975.75
Ready to retire?(Y/N)N
After year 8,your balance is 21,697.43
Ready to retire?(Y/N)
import java.util.*;

public class MyTest{
public static void main(String[] args){
Scanner in = new Scanner(System.in); System.out.print("How much money will you contribute every year");
double payment = in.nextDouble(); System.out.print("Internet rate in %: ");
double interestRate = in.nextDouble(); double balance = 0;
int year = 0; String input; //update account balance while user isn't ready to retire
do{
//add this year's payment and interest
balance += payment;
double interest = balance * interestRate / 100;
balance += interest; year++; //print current balance
System.out.printf("After year %d,your balance is %,.2f%n", year, balance); //ask if ready to retire and get input
System.out.print("Ready to retire?(Y/N)");
input = in.next();
}while(input.equals("N"));
}
}