Given a number N, Your task is to find the length of the longest consecutive 1s in its binary Test Case 1 Input (stdin) 1 14 Expected Output 3 Test Case 2 Input (stdin) 1 222 Expected Output 4
import java.util.*;
public class TestClass {
private static int maxConsecutiveOnes(int x)
{
int count = 0;
while (x!=0)
{
x = (x & (x << 1));
count++;
}
return count;
}
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int a=s.nextInt();
System.out.println(maxConsecutiveOnes(a));
}
}