SyntaxFix
Write A Post
Hire A Developer
Questions
Also possible to use reduce in Java 8 to solve this problem:
int res = "abdsd3$asda$asasdd$sadas".chars().reduce(0, (a, c) -> a + (c == '$' ? 1 : 0)); System.out.println(res);
Output:
3