Answer:
Check the explanation
Step-by-step explanation:
CODE IN JAVA:
StackDemo.java file:
import java.util.Stack ;
public class StackDemo {
public static boolean checkStringAmount(String s, char ch) {
Stack<Character> stack = new Stack<>();
for(int i = 0 ; i < s.length(); i++) {
if(s.charAt(i) == ch) {
stack.push(ch);
}
}
return stack.size() % 3 == 0 ;
}
public static void main(String[] args) {
System.out.println("checkStringAmount(\"zookeeper\", 'o') : " + checkStringAmount("zookeeper", 'o'));
System.out.println("checkStringAmount(\"zookeeper\", 'z') : " + checkStringAmount("zookeeper", 'z'));
System.out.println("checkStringAmount(\"zookeeper\", 's') : " + checkStringAmount("zookeeper", 's'));
System.out.println("checkStringAmount(\"zookeeper\", 'e') : " + checkStringAmount("zookeeper", 'e'));
}
}
Kindly check the attached image below to see the Code Output.