I am beginner in Java. I am trying to find compound interest using this program. I don't want to use pre-defined power function. I am not getting correct output.
What's wrong in this code?
Thanks for help.
class Main {
public static void main (String[] args) {
int P=0,Tm=0;
float R=0;
Scanner sc=new Scanner(System.in);
P=sc.nextInt();
R=sc.nextFloat();
Tm=sc.nextInt();
System.out.print(P*power((1+R/100),Tm));
}
static float power(float R,int Tm)
{
float sum=R;
for(int i=2;i<=Tm;i++)
{
sum*=R;
}
return sum;
}
}