- Feb 16, 2003
- 26,108
- 5
- 81
I need some help soon so I can continue working on my CS assignment, basically it has to check in a word if there are two letters next to each other that are the same. I have to file, one is the file with the main method and another with some other methods. Right now only the one actually checking for the repetition of two letters is under concern. Basically, its looking for words like MOON and SOCCER not SUN and HOCKEY.
Here's the code for the method:
Here is where it is returned:
When I run it, I get a string out of range error. I have narrowed it down to an error in either the 1st if statement of the method called or the boolCheck = line in the second quotation.
Mods: I really need an answer soon! Due tomorrow!
Here's the code for the method:
public static boolean checkCooney(String strCheck)
{
int numTimes = 0;
boolean boolCheck = false;
while(numTimes <= strCheck.length())
{
if(String.valueOf(strCheck.charAt(numTimes)) == String.valueOf(strCheck.charAt(numTimes+1)))
{
numTimes = strCheck.length() + 1;
return boolCheck = true;
}
if (numTimes == strCheck.length())
{
return boolCheck = false;
}
numTimes++;
}
return boolCheck;
}
Here is where it is returned:
boolCheck = cooneyRoutines.checkCooney(strInput);
if(!boolCheck)
{
System.err.println("No, Cooney doesn't like it");
break;
}
if(boolCheck)
{
System.err.println("Yes, Cooney likes it");
break;
}
numTimes++;
When I run it, I get a string out of range error. I have narrowed it down to an error in either the 1st if statement of the method called or the boolCheck = line in the second quotation.
Mods: I really need an answer soon! Due tomorrow!