-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay45_prob2.java
More file actions
53 lines (41 loc) · 1.24 KB
/
Day45_prob2.java
File metadata and controls
53 lines (41 loc) · 1.24 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
You are given a class Solution and an inner class Inner.Private. The main method of class Solution takes an integer as input. The powerof2 in class Inner.Private checks whether a number is a power of . You have to call the method powerof2 of the class Inner.Private from the main method of the class Solution.
Input Format
8
Constraints
1<=num<=2^30
Output Format
8 is power of 2
Sample Input 0
67
Sample Output 0
67 is not a power of 2
*/
// Kirtan Jain
import java.io.*;
import java.util.*;
public class Solution {
class Inner {
boolean check(long n){
for(int i=0;i<30;i++){
if(Math.pow(2,i)==n){
return true;
}
}
return false;
}
}
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
Solution ob = new Solution();
Solution.Inner obj = ob.new Inner();
if(obj.check(n)){
System.out.println(n + " is power of 2");
}
else{
System.out.println(n+ " is not a power of 2");
}
}
}