int foo(String s) {
if (s.equals("hello")) {
bar(s);
return s.length();
} else {
return bar(s).length();
}
}
String bar(String t) {
String s = "good";
if (t.equals("bye")) {
return s;
} else {
return s+t;
}
}
Result of calling foo("hello)
; answer is 5
Entering foo, String s = hello
Do the characters of s (hello) == hello?
Yes, call bar(hello)
Entering bar, String t = hello
Do the characters of t (hello) == bye?
No, returning goodhello
This is after the bar(s) call in foo: returning s.length which is 5
Result of calling foo("bye");
answer is 4
Entering foo, String s = bye
Do the characters of s (bye) == hello?
No
returning bar(bye).length()
Entering bar, String t = bye
Do the characters of t (bye) == bye?
Yes, returning good
bar(bye).length() came back with a value of 4