Find whether a given number is a power of 4 or not | Java program to check if given number is power of 4 or not ; 0 is not considered as a power of 4 ; Driver code
import java . util . * ; class GFG { static double logn ( int n , int r ) { return Math . log ( n ) / Math . log ( r ) ; } static boolean isPowerOfFour ( int n ) { if ( n == 0 ) return false ; return Math . floor ( logn ( n , 4 ) ) == Math . ceil ( logn ( n , 4 ) ) ; } public static void main ( String [ ] args ) { int test_no = 64 ; if ( isPowerOfFour ( test_no ) ) System . out . print ( test_no + " ▁ is ▁ a ▁ power ▁ of ▁ 4" ) ; else System . out . print ( test_no + " ▁ is ▁ not ▁ a ▁ power ▁ of ▁ 4" ) ; } }