public class SortaRecursive { public static void main(String[] args) { long[][] context=new long[10][2]; //each will be an N:V tuple int target=5; int pos=0; //Let's initialize: context[pos][0]=target; //Now the 'forwards pass', loading in all of the N's while (context[pos][0]>0) { context[pos+1][0]=context[pos][0]-1; pos++; } //On the 'return trip', perform the multiplications, storing the result while (pos>=0) { if (context[pos][0]<=0) //terminal case context[pos][1]=1; else //equivalent of recursive case: use the result of the previous (deeper) context context[pos][1]=context[pos][0]*context[pos+1][1]; pos--; } //the 'result' area of the lowest/oldest context has the answer: System.out.println(context[0][1]); } }