2 Replies Latest reply on Nov 17, 2006 1:46 PM by 807607

    Specify characters in a string

      I'm a beginner at Java.

      I need to create a program that will validate only binary characters in a string and count the number of 0s in the string. For some reason I keep getting an error message. For the life of me, I can't figure it out.

      char a = '1';
      char b = '0';
      int hmo;
      int totalzeroes=0;
      String input = JOptionPane.showInputDialog(null, "Please Enter a Binary Number");
      for (hmo=0; hmo<input.charAt(hmo);hmo++)


      Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range:
           at java.lang.String.charAt(Unknown Source)
           at cop.main(cop.java:19)