Menu

Check a number whether it is power of 2 or not - Java Program

import java.util.*;
class Display_is_power_of_2{
public static void main(String args[])  { 

Scanner sc=new Scanner(System.in);
System.out.println("Enter the number : ");
int n = sc.nextInt();

while(n!=1)
{
if(n%2 != 0)
{
System.out.println("not a power of two");
return;
}
n = n/2;
}
System.out.println("power of two");


}}