this is a homework project that i have reached a dead end with.
the object of the program is to read a file, scan each line, cheack for brackets and then number them matching each opening and closing bracket.
however, when it reaches the first bracket, it runs a exception and i can not figure it out.
here is the main loop.
while(inPut.hasNextLine()){
isbracket =inPut.nextLine();
for (int i= 0; i <=isbracket.length() ; i++){
checkIt = Character.toString(isbracket.charAt(i));
System.out.print(CheckBracket(checkIt));}
}
}
here is the method i call to check for brackets
public static String CheckBracket(String checkIt){
int numBracket = 0;
String Checked ="";
if (checkIt.equals("{")){
numBracket++;
Checked = (checkIt) +numBracket;}
if (checkIt.equals("}") && numBracket > 0){
Checked = checkIt +Integer.toString(numBracket);
numBracket--;}
if (checkIt.equals("}") && numBracket == 0){
Checked = (checkIt) + numBracket;}
if (checkIt != null) {Checked = checkIt;}
return Checked;
this is the error
{java.lang.StringIndexOutOfBoundsException: String index out of range: 12
at java.lang.String.charAt(Unknown Source)
at MatchUp2.main(MatchUp2.java:40)
(line 40 is: checkIt = Character.toString(isbracket.charAt(i))
can some one please just point me in the right direction?