-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxExponent.java
More file actions
36 lines (35 loc) · 916 Bytes
/
Copy pathMaxExponent.java
File metadata and controls
36 lines (35 loc) · 916 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
32
33
34
35
36
import java.util.*;
public class MaxExponent{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.print("Enter a: ");
int a = sc.nextInt();
System.out.print("Enter b: ");
int b = sc.nextInt();
int res = findExponent(a, b);
System.out.print("Result: "+res);
sc.close();
}
private static int findExponent(int a, int b){
int max=0;
int num=0;
for(int i=a;i<=b;i++){
if(i%2==0){
int temp =count(i);
if(temp>max){
max=temp;
num=i;
}
}
}
return num;
}
private static int count(int i){
int e=0;
while(i%2==0 && i!=0){
e++;
i/=2;
}
return e;
}
}