RECURSION Means Repetition calling of anything again and again
This is one of the Traditional and important program to learn how Recursion works and ? is Recursion and Why Let me take an example of Calculating Factorial thier pseudocode will be like this
function factorial is:
input: integer n such that n >= 1 output: [n × (n-1) × (n-2) × … × 1] 1. if n is >= 1, return [ n × factorial(n-1) ] 2. otherwise, return 1 end factorial
now what happens here is that it always return [n*factorial(n-1)] which call itself over and over again
Now Let us consider Your Context
public class recursion { public static void main(String args[]) { rectest ob = new rectest(10);
//here you are initializing the object and calling its constructor and intializing the array having size of 10
int i ; for(i=0 ; i<10 ; i++) ob.values[i] = i ;
//Here you are assigning every member variable to a certain values like at position 0 value[0]=0
ob.printarray(10); //here u are printing the values of ten values which you have passed now Important thing occurs here
} } Now Look at the printarray() Method here
void printarray(int i) { if(i==0) return ; else printarray(i-1); //printarray(i-1) here it calls the method itself so as to print all the values recursively System.out.print(values[i-1]+" "); }
thats it if you have more query ask
0 1 2 ... i want to understand this output and also what happens wheni==0and the return statement is executed ?