题解 | #求最大连续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 num = sc.nextInt();
String str = "";
while(num != 0){
if(num%2!=0){
str = 1 + str;
}else{
str = 0 + str;
}
num = num >>>1;
}
//System.out.println(str+"============");
String[] s = str.split("0");
int max = 0;
for(int i=0;i<s.length;i++){
if(s[i].length()>max){
max = s[i].length();
}
}
System.out.println(max);
}
}
}
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int num = sc.nextInt();
String str = "";
while(num != 0){
if(num%2!=0){
str = 1 + str;
}else{
str = 0 + str;
}
num = num >>>1;
}
//System.out.println(str+"============");
String[] s = str.split("0");
int max = 0;
for(int i=0;i<s.length;i++){
if(s[i].length()>max){
max = s[i].length();
}
}
System.out.println(max);
}
}
}