Monday, March 17, 2014

How to Check if a Number is Binary in Java - Programming Problem

Today we will take a look on another simple programming exercise, write a program to check if a number is binary in Java. A number is said to be binary if it only contains either 0 or 1, for example 1010 is binary number but 1234 is not. You can not any library method to solve this problem, you need to write a function to check if given number is binary, you can use basic constructs of Java programming language e.g. operators, keywords, control statements etc. If you are a regular reader of Javarevisited, then you know that I love to share simple programming problems here, because they serve two purposes, first they help beginners to apply their basic knowledge to do something which looks challenging at first, and second they serve as good coding questions to differentiate candidates on Java interviews between who can program and who can not. FizzBuzz is one of such problems but their are lot many, e.g. Prime numbers, Fibonacci series or factorial. But if you truly want to test your candidate then you need to give them some questions which are not so popular. If a candidate can apply his programming knowledge to a problem he is seeing first time, he is probably going to perform better than the candidate who has already seen the problem. That's why I was always looking at programming problems, which are not difficult to solve but has some element of freshness and not so common. This problem of checking whether a number is binary or not is not very different from converting a decimal to binary, but it will pose challenge for those programmers who can't code. By the way, if you are looking for simple programming problems, you can check my list of Top 30 programming interview questions, their I have shared questions from several popular topics including String, Array, Data Structure and Logic.
Read more �

No comments:

Post a Comment