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
Get step-by-step solutions from verified subject matter experts
