I've searched all over in the last couple hours and I just can't get a simple counter going in Java! I tried AtomicInteger and it's getAndIncrement() method but that didn't work.
Basically I have a for loop, and within that an if statement, I want an int to be incremented by 1 everytime in the for loop the if statement equates to true. And then after the for loop, return the int.
The int doesn't increment.
Help!
Edit - It's on Eclipse for Android:
public int markTest(Map<Long, String> selectedAnswers,
Map<Long, String> correctAnswers) {
int mark = 0;
for (long i = 1; i <= selectedAnswers.size(); i++) {
String userSelection = selectedAnswers.get(i).toString();
if (userSelection == correctAnswers.get(i))
mark++;
}
return mark;
}