Java Program To Calculate Power of a Number using pow() function
- May 29, 2020
- by

Java Program To Calculate Power of a Number using pow() function
In this Java Program, we calculate the power of the number using while loop.
The Power (exponent) of the numbers says how many times to use the number in a multiplication. It is written in a small number right and above the base number.
E.g. the little 3 says to use 10 two times in a multiplication.
103 = 10 * 10 * 10 = 1000
Logic : result = Math.pow(number, p);
Step 1 : Create the variables named as number and p and store 10 in number and 3 in p.
Step 2 : Create variable result, Use the Math.pow() function to calculate the power of the number and store the result in the variable named result.
Step 3 : Display the result by using the System.out.print.
Program :
public class Power2
{
public static void main(String[] args)
{
int number = 10, p =3;
double result = Math.pow(number, p);
System.out.println(number+"^"+p+"="+result);
}
}
Output:
10^3 = 1000
For execution of the same do visit my YouTube Channel:

0 comments:
Post a Comment