Question: How would I solve this if the second input of count (String str, char character ) is a char and not a string like in
How would I solve this if the second input of count (String str, char character) is a char and not a string like in the following program? { public static void main (String [] args) { System.out.println (count ("heloo anna", "a")); }
public static int count(String str, String character) { if(str.length()==0) { return 0; }
if ((str.substring(0,1).equals(character))) { return 1 + count(str.substring(1), character); }
return countChar(str.substring(1), character); } }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
