Created
December 20, 2016 03:43
-
-
Save NaotoKumagai/1fbb85c0c80029dcb6bf18ad8547cf8e to your computer and use it in GitHub Desktop.
day10:2進変換して"1"が続く最大数の出力
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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