复利计算
1 import java.util.Scanner; 2 3 public class Fulijisuan { 4 5 public static void main(String[] args) { 6 // TODO Auto-generated method stub 7 double N=1; 8 Scanner scanner=new Scanner(System.in); 9 System.out.print("若要计算本金请按3否则按0:"); 10 int num=scanner.nextInt(); 11 if(num==3){ 12 double money; 13 float year=30; 14 float total=3000000; 15 double a=0.30; 16 for(int j=1;j<=year;j++){ 17 N=(1+a)*N; 18 } 19 money=total/N; 20 System.out.println("需要本金:"+money); 21 } 22 System.out.print("请选择复利计算(1)or单利计算(2):"); 23 int choose=scanner.nextInt(); 24 25 System.out.print("请输入本金:"); 26 float P=scanner.nextInt(); 27 System.out.print("请输入利率:"); 28 float i=scanner.nextFloat(); 29 System.out.print("存入时间:"); 30 float n=scanner.nextFloat(); 31 32 if(choose==1){ 33 fuli(N, P, i, n); 34 } 35 else if(choose==2){ 36 danli(P, i,n); 37 } 38 39 } 40 41 private static void danli(double P, double i,double n) { 42 double G; 43 44 G=P+P*i*n; 45 System.out.print("单利终值为:"+G); 46 } 47 48 private static void fuli(double N, double P, double i, double n) { 49 for(int j=1;j<=n;j++){ 50 51 N=(1+i)*N; 52 } 53 double F; 54 F=P*N; 55 System.out.print("复利终值为:"+F); 56 } 57 58 59 }