Answer to Question #258484 in Java | JSP | JSF for JONIE

Question #258484

Write iterative and recursive functions that return value of

b

n

,


the nth power of


1
Expert's answer
2021-10-29T01:50:00-0400
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;
   }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS