java power without math code example
Example: 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);
}
}