Consider the following fragment of code below What is the ou

Consider the following fragment of code below What is the output of rec(4) ? public static void rec(int n) {if (n

Solution

Please find the answers below:

2)

rec(4) => if(4<=0) : false; thus print 4 and call rec(3)

rec(3) => if(3<=0) : false; thus print 3 and call rec(2)

rec(2) => if(2<=0) : false; thus print 2 and call rec(1)

rec(1) => if(1<=0) : false; thus print 1 and call rec(0)

rec(0) => if(0<=0) : true; thus return

Therefore the output will be : 4 3 2 1

Answer: A) 4 3 2 1

Question 3)

Answers) B. Nothing its an incorrect call, beacuse the array elements are like>

0: red, 1: zero, 2:blue, 3:one, and 4:green

 Consider the following fragment of code below What is the output of rec(4) ? public static void rec(int n) {if (n SolutionPlease find the answers below: 2) rec

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site