Page 1 of 1

QUESTION 1 (10 Marks) A) Given the following recursive method definition, analyse the coding. static int leng (String st

Posted: Thu Jul 14, 2022 2:10 pm
by answerhappygod
Question 1 10 Marks A Given The Following Recursive Method Definition Analyse The Coding Static Int Leng String St 1
Question 1 10 Marks A Given The Following Recursive Method Definition Analyse The Coding Static Int Leng String St 1 (50.67 KiB) Viewed 30 times
QUESTION 1 (10 Marks) A) Given the following recursive method definition, analyse the coding. static int leng (String str) i if (str == null || str. equals ("")) return 0 ; else return 1+ leng(str.substring (1); \} Show the tracing and the value returned from this method, if the following call is made. (4 marks) a) leng ("0") b) leng ("Ace") B) Given the following recursive definition for foo(n) where n is a non-negative integer. (6 marks) f∘o(n)=⎩⎨⎧​23foo(n−1)+foo(n−2)​,n=1,n=2,n>=3​ a) Write the definition of the recursive function foo(n) in JAVA. b) Trace and show the output for function foo(3). Show all steps taken