题解 | #求最大连续bit数#
求最大连续bit数
https://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2
import java.util.Scanner; import java.util.Arrays; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { int n = in.nextInt(); String str = Integer.toBinaryString(n); String[] a = str.split("0"); int l = a.length; int[] arr = new int[l]; for (int i = 0; i < l; i++){ arr[i] = a[i].length(); } Arrays.sort(arr); System.out.print(arr[l-1]); } } }