Answers for "java program to check whether number is power of two or not"

0

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;
 }
 }
 
Posted by: Guest on February-22-2021

Code answers related to "java program to check whether number is power of two or not"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language