首页 > 代码库 > 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