码迷,mamicode.com
首页 > 编程语言 > 详细

java day1

时间:2017-02-28 20:55:45      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:[]   mon   read   break   void   bsp   bre   logs   sof   

 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

标签:[]   mon   read   break   void   bsp   bre   logs   sof   

原文地址:http://www.cnblogs.com/xiaolei-meow/p/6480690.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!