title: Check if the input number is in a valid binary format
body: <p>i tried to make a simple program,which check if the input number from the user is a binary number and that number is in correct binary format  -> without leading zeros. That below is my code,but it doesn't work. I would appreciate if someone could help.</p>
  
  <pre><code>    public class CheckNumberBinary {
      public static void main(String args[]) {
          int r = 0, c = 0, num, b;
  
          Scanner sl = new Scanner(System.in);
          num = sl.nextInt();
         int firstDigit = Integer.parseInt(Integer.toString(num).substring(0, 1));// i want to get the first digit from the input
          if (firstDigit&gt;0||firstDigit==1 ){
              while (num &gt; 0) {
                  if ((num % 10 == 0) || (num % 10 == 1))
                      c++;
                  r++;
                  num = num / 10;
              }
              if (c == r) {
                  System.out.println(true);
              } else
                  System.out.println(false);
          } else System.out.printf("WARNING: The number starts with 0");
      }
  }
  </code></pre>