1. 题目
读题
考查点
2. 解法
思路
代码逻辑
具体实现
public class HJ086 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(countOne(sc.nextInt()));
}
public static int countOne(int n) {
int max = 0;
int cnt = 0;
while (n > 0) {
if ((n & 1) == 1) {
cnt++;
max = Math.max(max, cnt);
} else {
cnt = 0;
}
n = n >>> 1;
}
return max;
}
}