- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpowerOfTwo.java
More file actions
Latest commit
24 lines (18 loc) · 453 Bytes
/
Copy pathpowerOfTwo.java
File metadata and controls
24 lines (18 loc) · 453 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
packageBit_Manipulation;
importjava.util.Scanner;
publicclasspowerOfTwo {
publicstaticvoidmain(String[] args){
Scannersc=newScanner(System.in);
System.out.print("Enter a number to check: ");
intx=sc.nextInt();
if(isPowerOfTwo(x)){
System.out.println("Power of two!");
}else{
System.out.println("Not a power of two!!");
}
sc.close();
}
staticbooleanisPowerOfTwo(intn){
return (n>0)&&((n&(n-1))==0);
}
}