Self referencing variables in a for loop

java

#1

Hello,

I am trying to write a code that takes a String (str) and finds the positions of any ‘*’ characters. I am trying to write a for loop like this:

 for(int i = str.indexOf('*',0); i< str.length(); i = str.indexOf('*',i)+1) {  

basically I want my variable ‘i’ to become the integer 1 larger than the position of the ‘*’.

However I am getting an error ‘unreachable statement’. Not sure what’s going on here.

The problem I am working on can be found here
http://codingbat.com/prob/p139564


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.