Java.
Implement the countNotMatching method below, which takes as input a string and a character and returns how many characters in the string are NOT the supplied character. An example main method, as well as corresponding output, is supplied – you cannot change this method, and the output when the program is run must conform exactly to the sample output.
/* sample run:
Other characters: 1
Other characters: 3
Other characters: 3
*/
public static void main(String args[]) {
System.out.printf("Other characters: %d%n", countNotMatching("Foo", 'o'));
System.out.printf("Other characters: %d%n", countNotMatching("Bar", 'b'));
System.out.printf("Other characters: %d%n", countNotMatching("Baz!", 'B'));
}
// put your countNotMatching method here
public class CountNotMatching {
/* sample run:
Other characters: 1
Other characters: 3
Other characters: 3
*/
public static void main(String args[]) {
System.out.printf("Other characters: %d%n", countNotMatching("Foo", 'o'));
System.out.printf("Other characters: %d%n", countNotMatching("Bar", 'b'));
System.out.printf("Other characters: %d%n", countNotMatching("Baz!", 'B'));
}
public static int countNotMatching(String s, char ch) {
int count = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != ch) {
++count;
}
}
return count;
}
// put your countNotMatching method here
}

Java. Implement the countNotMatching method below, which takes as input a string and a character and...