calculate pow in java code example
Example 1: how to find powers in java
int n=Math.pow(N, P);
Example 2: Write a method that raises a number to a power without using Math.pow() method
public class Power {
public static void main(String[] args) {
int base = 3, exponent = 4;
long result = 1;
while (exponent != 0)
{
result *= base;
--exponent;
}
System.out.println("Answer = " + result);
}
}