I am trying to print odd numbers between 2 numbers.
if left= 3, right = 9 then the program should print 3,5,7,9 and the program is working well.
but if left = 9 and right = 3, i.e left > right then the list is returning empty.
Can anyone of you please let me know what is the issue? Thank you.
Thank you so much Swasthik and Sharma for providing the quick solution and the code is working just perfect. It would have been easy to understand if you could have explained me what was wrong in my code. I could print the list in line 35 (just before returning the list) but when I return the list it is returning empty. As mentioned by Swasthik, after adding return statement [return Between(left, right);] it is working fine.
I usually delete complete solutions; see what it says on the title page for this forum:-
We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
But I can see enough confusion that I think I shall let your suggestion stand for improvements.
What is wrong with iterating from 9 to 3 and getting an empty List? My first thought is, that would produce an empty List. What would you like to happen? What is to happen if you pass a negative number: what should the result be of passing −16 and −4, for example?
and POOF! You're gone! But look, this tiny ad is still here: