checking if a number is a power of 3 java code example
Example 1: how to find power of a number in java
int powerOfNumber = (int) Math.pow(number, power);
Example 2: how to check if a number is a power of 2 java
//create a boolean method that checks if number is a power of 2 by using modulus
public static boolean powerOfTwoGeneral(int n)
{
while(n%2==0)
{
n=n/2;
}
if(n==1)
{
return true;
}
else
{
return false;
}
}