write a java program to check whether given number is binary or not
import java.util.Scanner;
public class CheckNumberisBinary
{
public static void main(String args[])
{
int r=0,c=0,num,b;
Scanner sl=new Scanner(System.in);
System.out.println("Enter a number");
num=sl.nextInt();
b= num;
while(num>0)
{
if((num %10==0)|| (num%10==1))
c++;
r++;
num=num/10;
}
if(c==r)
System.out.println(b+" is a Binary Number.");
else
System.out.println(b+" is not a Binary Number");
}
}
Also in Java:
- how to return the first character in an array from a method java
- web app runtime for java
- enumerated data types in java
- getordefault java
- read csv java android
- print map java
- how to remove all whitespace from string java
- java how to get current date
- java how to get all threads
- for each loop java
- java string to byte array utf8
- how to set frame colo in java
- How can I put a parameter into a localized string in Android?
- java final modifier on method
- java get input
- get drawable with string android java
- funzione random in java
- android java shared preferences remove key
- testing the web layer without authentication spring
- palindrome function java
- processing sound android
- java override equals and hashcode
- java projects
- how to break from a loop in java