求最大连续bit数
求最大连续bit数
http://www.nowcoder.com/questionTerminal/4b1658fd8ffb4217bc3b7e85a38cfaf2
import java.util.Scanner;
public class Main {
private int countBiggestOf1(int n) {
int res = 0;
int temp = 0;
while (n != 0) {
if ((n & 1) == 1) {
temp++;
}
else {
temp = 0;
}
n = n >>> 1;
res = Math.max(res, temp);
}
return res;
}
public Main() {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {
int n = in.nextInt();
int res = countBiggestOf1(n);
System.out.println(res);
}
}
public static void main(String[] args) {
Main solution = new Main();
}
}