I've been working on a recursive solution for assessing whether a number is binary or not. However my solution always returns false and I can't seem to get the logic correct. My code is below:
public class Convert{
public static boolean isBinaryNumber(int binary){
int temp = 0;
boolean status = false;
if(binary==0 || binary==1) {
status = true;
return status;
}
else {
temp = binary%10;
if(temp == 1 || temp == 0) {
binary = binary/10;
isBinaryNumber(binary);
}
else {
status = false;
return status;
}
}
return status;
}
public static void main(String a[]){
System.out.println("Is 1000111 binary? :"+ isBinaryNumber(1000111));
System.out.println("Is 10300111 binary? :"+ isBinaryNumber(10300111));
}
}