Program to check if a number can be expressed as an even power of 2 or not | Java program for the above approach ; Function to check if N can be expressed as an even power of 2 ; Iterate till x is N ; if x is even then return true ; Increment x ; If N is not a power of 2 ; Driver Code
import java . io . * ; class GFG { static boolean checkEvenPower ( int n ) { int x = 0 ; while ( x < n ) { int value = ( int ) Math . pow ( 2 , x ) ; if ( value == n ) { if ( x % 2 == 0 ) return true ; else return false ; } x ++ ; } return false ; } public static void main ( String [ ] args ) { int N = 4 ; System . out . println ( ( checkEvenPower ( N ) ? " Yes " : " No " ) ) ; } }