Saturday, 4 January 2014

raw code: Compound Interest calculation in Java [ simple, user friendly]

Q: lets say, you to find out what will be the number of viewers in my blog in next 30 days. given that, for instance i have 10,000 views now, increasing rate is 1% each day. you have to calculate it for next 30 days and show the result in every other 10th day.
formula is: amount= pri(1+rate)^time

=>
import java.util.Scanner;

class grps{
    public static void main(String[] agrs){
        Scanner input= new Scanner(System.in);
        int y=0;
       
        System.out.print("enter the sum you have already: ");
        double principal=input.nextDouble(); //=10000
       
        System.out.print("how much is the growth rate: ");
        double rate=input.nextDouble();    //=.01
       
        System.out.print("for how many days you want to calculate: ");
        double day=input.nextDouble();    //=30
       
        System.out.print("how often you want to see the result [e.g: 1 being every day, 2 being every other day]: ");
        double show=input.nextDouble();    //=10
       
        for(int x=1; x<=day; x+=show){
            y+=(int)(principal*Math.pow(1+rate, day));
            System.out.println("In "+x+" days there will be "+y+" followers!");
        }
    }
}

1 comment:

  1. Vip Investment Club - 100% Hourly For 72 Hours
    Vip Investment Club is a long term high yield private program, backed up by Forex market trading and investing in various funds and activities. Profits from these investments are used to enhance our program and increase its stability for the long term.
    Invest Here
    http://www.vipinvestment.net
    Investment Insurance
    http://www.payinghyiponline.com/vipinvestment.html

    ReplyDelete