Count the number of positive integers in input.
String s; // current string in input
int counter;
counter = 0;
s = JOptionPane.showInputDialog("Input an integer");
while (s != null) {
if (Integer.parseInt(s) > 0)
counter++;
s = JOptionPane.showInputDialog("Input an integer");
}
System.out.println("Number of positive integers in input = " + counter);
In this case, the increment of the counter depends on a condition.