Declare and initialise the integer outside the method (but inside the class). That way each invocation of the method will use the same shared ineteger.
JamesCherrill
... trying to help
8,527 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,456
Skill Endorsements: 30
Or pass the value which you want to use in the loop inside to the recursive method. That way, the value will be updated every time you call.
// i.e.
public simpleRecursive(int val) {
if (val>0) {
for (int i=0; i<val; i++) { System.out.print(i+" "); }
System.out.println("");
simpleRecursive(val-1);
}
}
// and call it
simpleRecursive(4);
// result will be...
// 0 1 2 3
// 0 1 2
// 0 1
// 0
Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 375
Skill Endorsements: 17