Write a Java program to check whether an given integer is a power of 4 or not.

 /* Write a Java program to check whether an given integer is a power of 4 or

not.

Given num = 64, return true. Given num = 6, return false. */

import java.util.*;

class Eight

{

public static void main( String arg[] )

{

Scanner obj = new Scanner( System.in );


int a, x = 1;


System.out.print("\nEnter any number to check\nnumber is power of 4 or not : ");

a = obj.nextInt();


outer:

if( a>4 )

{

for (int i=1 ; i<=a ; i++ )

{

x = x * 4;


if(x == a)

{

System.out.println("\n\t => True <=");

break outer;

}

else if( x > a )

{

System.out.println("\n\t => False <=");

break outer;

}

}

}

else

{

System.out.println("\n\t => False <=");

break outer;

}

}

}

More Information on our channel Programmer Community

please like , share and subscribe to get notifications of new videos....

To understand this program video will coming soon on our you tube channel



Comments

Popular posts from this blog

Design and Develop a java program to read marks of a student and print the total and average of marks using scanner class.

Write a Java program to convert seconds to hour, minute and seconds.

Write a Java program to print the ascii value of a given character.