+ 2
How the function is subtracting the numbers?
public class Program { public void fnRec(int p,int q){ if(p>q) { return; } System.out.print("\n ---"+p); fnRec(p+1,q); System.out.print("\n +++"+p);} public static void main(String[] args) { Program ob=new Program (); ob.fnRec(5,9); } } output = ---5 ---6 ---7 ---8 ---9 +++9 +++8 +++7 +++6 +++5 you may also check by this link below 👉 https://code.sololearn.com/cLjIpcIbZ2W5/?ref=app
1 Antwort
+ 1
fnRec function doesn't subtract anything it's just outputting '+++' part reverse because that statement is after the recursive method fnRec