How can I make a recursive version of my iterative method?
- by user247679
Greetings. I am trying to write a recursive function in Java that prints the numbers one through n. (n being the parameter that you send the function.) An iterative solution is pretty straightforward:
public static void printNumbers(int n){
for(int i = 1; i <= n; i++){
System.out.println(i);
i++;
}
As a novice programmer, I'm having troubles figuring out how a recursive version of this method would work. Any bright ideas? Thanks for reading my problem!