How to use the continue statement in Java

1 Answer

0 votes
package javaapplication1;

public class Example {
    public static void main(String[] args) {
             
        String s = "Java programming language";
        int count = 0;
        char countChar = 'a';
       
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != countChar)
                continue; // skip count++;
            count++;
        }
        System.out.println("There are " + count + " '" + countChar + "' characters") ;
    }

}


/*
run:
 
There are 5 'a' characters
 
*/

 



answered Jan 15, 2016 by avibootz

Related questions

2 answers 288 views
1 answer 150 views
1 answer 233 views
1 answer 181 views
1 answer 144 views
144 views asked Aug 30, 2016 by avibootz
...