Preview:
class CountingAsterisk {
    public static void main(String[] args) {
        System.out.println(countAsterisks("iamprogrammer"));
    }

    public static int countAsterisks(String s) {
        int count = 0;
        int localCount = 0;
        for (int i = 0; i < s.length(); i++) {
            if (localCount % 2 == 0) {
                if (s.charAt(i) == '*') {
                    count++;
                }
            }
            if (s.charAt(i) == '|') {
                localCount++;
            }
        }
        return count;
    }
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter