What will this program print? public static void main(String[1 args) f System.ou
ID: 3739935 • Letter: W
Question
What will this program print? public static void main(String[1 args) f System.out.println(f ( "abc" )); public static String f (String s) ( if (s.length)Explanation / Answer
s is "abc" length of s is 3 (s.length() / 2) is 1 prints "before abc" String x = f(s.substring(0, s.length()/2)); // so, s is f(s.substring(0, 1)) which is f("a") => "a" String y = f(s.substring(1)) // y = "bc" => s is "bc" length of s is 2 (s.length() / 2) is 1 prints "before bc" String x = f(s.substring(0, s.length()/2)); // x = f("b") => x = "b" String y = f(s.substring(1)); => y = "c" String z = "bc"; prints "after bc" String z = "ab" prints "after ab" print "ab" output: before abc before bc after bc after ab ab
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.