Answers for "write a program to determine if a number is power of 2 or not in java"

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 "write a program to determine if a number is power of 2 or not in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language