void storedata(int i) {
if(i > 0) {
a[size-i] = in.nextInt();
storedata(i--);
}
}
The above code is not terminating after taking the required number of inputs. It runs forever. How can I solve this?
void storedata(int i) {
if(i > 0) {
a[size-i] = in.nextInt();
storedata(i--);
}
}
The above code is not terminating after taking the required number of inputs. It runs forever. How can I solve this?
You will always call storeData
recursively with the same value, because you used
storedata(i--);
Try using
storedata(--i);
instead. That will decrement i
first.