So let's take "banana", what happens when the program gets to if (ch <= 'd')? My understanding is the 'b' is < 'd' so it moves to the else. Am I wrong or right? If I'm right, then what happens at return 1 + g(s, index + 1);
public class Q7f
{
public static int g(String s)
{
return g(s, 0);
} // g()
public static int g(String s, int index)
{
if (index >= s.length())
return 0;
char ch = s.charAt(index);
if (ch <= 'd')
return 1 + g(s, index + 1);
else
return g(s, index + 1);
} // g()
public static void main(String[] args)
{
System.out.println(g("banana"));
System.out.println(g("cat"));
System.out.println(g("dog"));
} // main()
} // class Q7f