Skip to content

Instantly share code, notes, and snippets.

@NaotoKumagai
Created December 20, 2016 03:43
Show Gist options
  • Save NaotoKumagai/1fbb85c0c80029dcb6bf18ad8547cf8e to your computer and use it in GitHub Desktop.
Save NaotoKumagai/1fbb85c0c80029dcb6bf18ad8547cf8e to your computer and use it in GitHub Desktop.
day10:2進変換して"1"が続く最大数の出力
import java.io.*;
import java.util.*;
import java.util.stream.Stream;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.close();
String binaryString = Integer.toBinaryString(n);
String[] numbers = binaryString.split("0");
Stream.of(numbers)
.max(Comparator.comparing(String::length))
.ifPresent(s -> System.out.print(s.length()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment