Day 10: Binary Numbers | 30 Days of Coding | HackerRank | Java Language

**Before watching this make sure that you’ve tried enough**
Language: Java 7

import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(;
        int n = in.nextInt();
        // first: we will convert the decimal value into a binary string using the method
        // second: we will count the consecutive 1
        char[] BinaryArray = Integer.toBinaryString(n).toCharArray();
        int Count_One = 0;
        int Max_One = 0;
        for(int i = 0;i < BinaryArray.length;i++){
            if(BinaryArray[i] == '1')Count_One++;
            else Count_One = 0;
            if(Count_One > Max_One){
                Max_One = Count_One;


If this solution helped you, please share this with your friends.
And if you have anything to say, let me know in the comment section.
More solutions are coming so Like our Facebook page and Subscribe to our YouTube channel to stay connected.

Leave a Comment