This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
that 'int' part says "this method will return an int primitive".
But you never do. Nowhere in the method do you have a return statement. I'm guessing you are missing a "return upperCaseCount ;" statement somewhere after the close of the outer for-loop - probably between your lines 27 and 28.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Joined: Oct 08, 2011
I put the return statement in and my code compiled but I am still having a problem....
Once I entered a string into the compiler to test it, it gave me the following error
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
ex out of range: 1
The problem was that in my for loop, I had a "less than or equal", and was starting it at 0, so there was one extra character it was trying to check when it wasn't really there.
That is an EXTREMELY common error, especially for beginners. That was the first thing I looked for when I saw your code, and sure enough, there it was. But just TELLING you that wouldn't have been nearly as educational for you. Now you will be more likely to not make that same mistake again (although everyone does at some point), but more importantly, you have an excellent debugging tool on your belt now.
I would have thought you don’t usually get an out of bounds exception at 1 by iterating an empty String; I would have thought you suffer that Exception at index 0 on an empty String. An empty String doesn’t even have a charAt(0).