Java Program to Calculate Power of a Number

In this tutorial, I am going to explain how to calculate power of a number without using Math.pow method in java.

For example:

i) 23 = 8 (2 * 2 * 2)
ii) 52 = 25 (5 * 5)

In Java, we can easily calculate power of any number using java.lang.Math.pow() method. It returns the result after calculating the value of first argument raised to the power of the second argument.

Now, Think for a moment how we can calculate power of a number without using Math.pow() in java. In this tutorial, I am going to explain iterative and recursive approach to calculate power of a number.

Calculate power of a number

Calculate power of a number

Java Program to Calculate Power of a Number

In this java code example, We are going to use iterative approach to calculate power of a number. In this program, we have declared two variable base and exponent. Using while loop, we keep on multiplying result by base until exponent becomes zero.

Subscribe Our Tutorials

Get Latest Updates on Facebook

Java Program to Calculate Power of a Number using Recursion

In this example, we are calculating power of a number using recursion. If you are not familiar with recursion then check my previous tutorials on recursion.

Recursion vs Iteration – Difference between recursion and iteration

In this video tutorial, i have explained how we can calculate power of a number without using Math.pow() method.

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , . Bookmark the permalink.