Question: Write a method called isBinary that takes an integer n as a parameter and determines if that number could be read as a binary number.

Write a method called isBinary that takes an integer n as a parameter and determines if that number could be read as a binary number. The method should return True if the number is a binary; and False if the number is not a binary number.

Example method calls:

isBinary(1) // returns true; all digits are 0 or 1
isBinary(10001) // returns true; all digits are 0 or 1
isBinary(10501) // returns false; one of the digits is not 0 or 1
isBinary(642) // returns false; multiple digits are not 0 or 1

You may assume that the number passed to your method is not negative, but it might be 0.

You may not convert the number to a string to solve this problem.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!