首页 > 代码库 > java day1
java day1
1 import java.util.Scanner;
2 public class Practice {
3 public static void main(String[] args){
4 Scanner in = new Scanner(System.in); //构造一个对象
5 System.out.print("How muuch do you need to retire?");
6 double goal = in.nextDouble(); //获得输入
7 System.out.print("How much money will you cotribute every year?");
8 double payment = in.nextDouble();
9
10 System.out.print("Interest rate in %: ");
11 double interestrate = in.nextDouble();
12
13 double balance = 0;
14 int years = 0;
15 read_Date:
16 while(balance < goal){
17 balance += payment;
18 double interest = balance * interestrate / 100;
19 balance += interest;
20 years++;
21 if(balance > goal)
22 break read_Date;
23 }
24 System.out.println("You can retire in " + years + " years");
25 }
26 }
java day1
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。