2 Replies Latest reply: Nov 17, 2006 7:46 AM by 807607 RSS

    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)