题解 | #求最大连续bit数#
求最大连续bit数
https://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { int b = scanner.nextInt(); int continueCount = 0; int max = 0; while (b > 0) { if ((b & 1) == 1) { max = Math.max(++continueCount, max); } else { continueCount = 0; } b >>= 1; } System.out.println(max); } } }