The next problem is based on Binary numbers.The number to binary conversion and vice versa is the motive of this day. Again I would recommend to watch the tutorial for this lesson, it will brief you about the mathematics involved in conversion.

**Task **

Given a base-10 integer,n , convert it to binary (base-)2. Then find and print the base- integer denoting the maximum number of consecutive ‘s in ‘s binary representation.

**Sample Input**

1 |
5 |

**Sample Output**

1 |
1 |

**Sample Input**

1 |
13 |

**Sample Output**

1 |
2 |

So here the Solution you have landed here for..

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import java.io.*; 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(System.in); int n = in.nextInt(); int count=0,min=0; while(n>0) { if(n%2==1) { count++; if(count>=min) { min=count; } } else { count=0; } n=n/2; //System.out.println(n); //System.out.println(min); } System.out.println(min); } } |

Hope you like the post.. 🙂

Your opinion on options differs from most of the blogs I browse, I’m pleased.

can we get test cases of this problem of hackerrank

try 15,255,63,15743

I hope that it’s acceptable that I write about this with just a few

of my clients, this’ll help their knowledge of

binary tremendously.