-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExample4.java
More file actions
31 lines (25 loc) · 693 Bytes
/
Example4.java
File metadata and controls
31 lines (25 loc) · 693 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
28
29
30
31
package whileGita;
public class Example4 {
public static void main(String[] args) {
System.out.println(solution(64));
System.out.println(solution2(64));
}
// 2 4 8 16 32 64 128 256 ...
// 32 -> 2^k k=5
public static int solution(int n) {
int k = 1, degree = 0;
do {
k *= 2; // 2 4 8 16 32 64
degree++; // 1 2 3 4 5 6
} while (k < 0);
return degree;
}
public static int solution2(int n) {
int k = 1, degree = 0;
while (k < 0) {
k *= 2; // 2 4 8 16 32 64
degree++; // 1 2 3 4 5 6
}
return degree;
}
}