import java.util.*;
import java.lang.*;
import java.io.*;
// The main method must be in a class named "Main".
class Main {
static int Power(int n,int p){
if (p==0) // x⁰ =1
{
return 1;
}
if (p==1)// x¹ = x
{
return n ;
}
int powersub = Power(n,p-1);
int calc = n*powersub;
// System.out.println(calc);
return calc;
}
public static void main(String[] args) {
System.out.println("power calculate using recursion");
int num = 2 , power = 5;
int result = Power(num,power);
System.out.println(result);
}
}
To embed this program on your website, copy the following code and paste it into your website's HTML: