check the number is binary or not(using java)

 // a number is said to binary if all the digit should be either zero or one

ex-1011  binary number    ex-1201 not binary number


class binary

{

public static void main(String args[])

{

int  no=125,b=0,e=0;

while(no>0)

{

b=n0%10;

no=no/10;

if(b>1)

{

e=1;

break;

}

}

if(e==0)

System.out.println("the number is binary");

else

System.out.println("the number is not binary");

}

}

Comments

Post a Comment

Popular posts from this blog