We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
long m = n;
int maxCount = 0;
int count = 0;
long prev = -1;
while(m != 0) {
long current = m & 1;
if(current == 1 && current == prev) {
count++;
}else {
count = 1;
}
if(count > maxCount){
maxCount = count;
}
prev = current;
m = m >> 1;
}
System.out.println(maxCount);
in.close();
}
Day 10: Binary Numbers
You are viewing a single comment's thread. Return to all comments →
public static void main(String[] args) { Scanner in = new Scanner(System.in);