题解 | #求最大连续bit数#
求最大连续bit数
http://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
//转化成二进制串
String str = Integer.toBinaryString(n);
//对0进行分割,将连续的1都存到数组里
String[] arr =str.split("0");
int max=0;
for(String s :arr){
max=s.length()>max?s.length():max;
}
System.out.println(max);
}
}
}