- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPowerOfTwo.java
More file actions
Latest commit
27 lines (24 loc) · 691 Bytes
/
Copy pathPowerOfTwo.java
File metadata and controls
27 lines (24 loc) · 691 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
25
26
27
//Given an integer n, return true if it is a power of two. Otherwise, return false.
importjava.util.Scanner;
importjava.lang.Math;
classPowerOfTwo{
publicbooleanisPowerOfTwo(intn) {
booleana = false;
for(inti=0;i<n;i++){
if(n==Math.pow(2,i)){
a = true;
break;
}
else{
a = false;
}
}
returna;
}
publicstaticvoidmain(String[] args){
Scannerinput = newScanner(System.in);
intn= input.nextInt();
PowerOfTwoobj = newPowerOfTwo();
System.out.println(obj.isPowerOfTwo(n));
}
}