java - Print forward sequencing followed by backward sequencing till the beginning? -


i have interesting problem solve have given start , end integer values , need print start end , end start using recursion.

for example -

start = 2 , end = 5 method should print following,

2,3,4,5,4,3,2 

i can first part using code,

public static void countup(int start, int end) {          system.out.println(start);      if(start< end){          countup(start+1, end);     } } 

but, start value increased within recursion , don't have way find decrease. how can improve code mentioning 1 method allowed use ? currently, it's printing

2,3,4,5 // don't care commas   

countup(start+1, end); doesn't increase start - computes start+1 , passes result new invocation of countup, have its own value of start. inside current invocation, start still has same value. after recursive call has completed, control return current invocation , continue after call. happens if print start @ end of method?


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -