I have this code and I was just wondering is my understanding of it correct.
5 is passed into the method numbers and n now equals 5. The if statement is false and therefore it does the else statement, and does numbers(5-1)
and does the method numbers again and does NOT print out n or return yet.
Now n = 4 and the same method is repeated till n = 1 at which point it hits return? and so from this point it returns to where n = 2, follows the prints 2 (System.out part) and then returns, at which point it returns to n = 3, prints 3 and returns..and so on all the way to 5?
That is what i think is going on, could someone clarify this for me please, thank you!
public class test {
public static void main(String [] args){
numbers(5);
}
public static void numbers (int n){
if(n==1) return;
else{
numbers(n-1);
System.out.println(n);
return;
}
}
}