+ 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

21st Feb 2018, 1:11 PM
Aditya Sahu
Aditya Sahu - avatar
1 ответ
+ 1
fnRec function doesn't subtract anything it's just outputting '+++' part reverse because that statement is after the recursive method fnRec
22nd Feb 2018, 8:18 AM
Dipendra Shrestha
Dipendra Shrestha - avatar