title: How to convert large binary to decimal?
body: <p>It works when I enter binary like 10, 1011, 1101. But it always prints "Not binary" when I enter 10011010010, whereas it should be 1234. How to modify it?</p>
  
  <pre><code>import java.util.Scanner;
  public class Binary {
  
      public static int toDecimal(String b) {     
          int decimal = Integer.parseInt(b,2);
          return decimal;
      }
  
  
      public static boolean isBinary(String b) {
          int inputNum = Integer.parseInt(b);
  
          while(inputNum != 0){
              if(inputNum % 10 &gt; 1){
                  return false;
              }
              inputNum = inputNum / 10;
          }
          return true;
      }
  
      public static void main(String[] args) {
  
          System.out.print("Enter binary: ");
          Scanner in = new Scanner(System.in);
          String binaryNum = in.next();
  
          try{
              int intNum = Integer.parseInt(binaryNum);
  
              boolean isBinary = isBinary(binaryNum);
              if(isBinary){
                  int outputDecimal = toDecimal(binaryNum);
                  System.out.println("\n"+ outputDecimal +" in decimal");
              }else{
                  System.out.println("\n" + "Not binary!");
              }
          }catch(Exception e){
              System.out.println("\n" + "Not binary!");
          }
      }
  }
  </code></pre>