I have this section of code:
int numberStars =0;
int counter =0;
while (file.hasNext()) {
String contents = file.next();
{
if (contents.contains("*")) {
numberStars = counter;
continue;
}
counter++;
}
}
So if I have a text file containing something like
ha de fa * la we * ba *
The output will be 3,5,6. How do I change this loop so that the last * is not counted (so the 6 won’t be present), and also how would I ensure, that each time a value is assigned to numberStars, that value is then used in another part of the method?
Thanks a lot.
It looks like you might want to store a list of values of
counterinstead of just a singleint. Something like