4.Draw the recursive flow diagram/memory stack (draw each methods and their behavior in the way they are being called and executed) of the code given below: public class Surprise{ public static int mystery(int n) { System.out.println("h(" + n + ")"); if (n == 0) { System.out.println("value: 0"); return 0; } else { System.out.println("going down"); int temp = mystery (n - 1) + 1; System.out.println("h(" + n + ") --> " + temp); return temp; } } public static void main(String [] args){ mystery(4); } OR class Surprise: def mystery(self,n): print("h(" ,n,")") if(n==0): print("value: 0") return 0 else: print("going down") temp = self.mystery(n-1)+1 print("h(",n,") --> ",temp) return temp #Tester s = Surprise() s.mystery(4)
4.Draw the recursive flow diagram/memory stack (draw each methods and their behavior in
the way they are being called and executed) of the code given below:
public class Surprise{
public static int mystery(int n) {
System.out.println("h(" + n + ")");
if (n == 0) {
System.out.println("value: 0"); return 0;
} else {
System.out.println("going down");
int temp = mystery (n - 1) + 1;
System.out.println("h(" + n + ") --> " + temp);
return temp;
}
}
public static void main(String [] args){
mystery(4);
}
OR
class Surprise:
def mystery(self,n):
print("h(" ,n,")")
if(n==0):
print("value: 0")
return 0
else:
print("going down")
temp = self.mystery(n-1)+1
print("h(",n,") --> ",temp)
return temp
#Tester
s = Surprise()
s.mystery(4)
5.[Hard]
- Print the following pattern for the given input:
Input: 5
Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
- Print the following pattern for the given input:
Input: 5
Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images