Write iterative and recursive functions that return value of
b
n
,
the nth power of
public class HelloWorld{
public static void main(String []args){
System.out.println("The power n is: ");
System.out.println(calculatePower(5, 3));
}
public static int calculatePower(int base, int powerRaised){
if (powerRaised != 0)
return (base*calculatePower(base, powerRaised-1));
else
return 1;
}
}
Comments
Leave a comment