public static void main(String args)
int base = 5, exponent = 3;
long result = 1;
while (exponent != 0)
result *= base;
System.out.println("Answer = " + result);
Answer = 125
What is Long int in Java
What is While Loop and How to Execute for Power of Number in Java
The while loop in Java is a control flow statement that allows code to be repeated based on a Boolean condition using this method we can calculate power of number in java. The while loop is similar to a looping if statement. If the condition evaluates to true, the body of the loop will be executed, and we will proceed to the update expression.
Power of Number in Java Program for Calculation
In Java, the power function is used to calculate a number that has been raised to the power of another number. This method takes two parameters and returns the first parameter’s value multiplied by the second parameter’s value.
An exponent is a number or letter that is written above and to the right of the base in a mathematical statement. It denotes that the base will be raised to a given level of strength. The base is x, while the exponent or power is n to calculate power of number in java.