I++ or i+=1 has difference ? on recursion

public static boolean ispalindrom(String str,int si,int li){

			if(li <= si){
				return true ;

			}

			if(str.charAt(si) != str.charAt(li)){
				return false;
			}



			boolean res = ispalindrom(str,si+=1,li-=1);// s++ && li-- is  not work why ? i thing both are incrementing  or decrementing in same way .

			return res;
			

		}

Hi @amankumar7017,
The += and -= operators are shorthand for si=si+1 and li=li-1 while in parameter you do not have to change the value you only have to send the increased value recursively … therefore the correct parameters willl be si+1 and not si=si+1. Doing si=si+1 instead of si+1 changes the meaning as well as value of expression. And in other case if you want to increment the value so you must not do that in parameter like you have done in above provided code … Just increment before calling isPalindrom and then send incremented si in parameter and the code will again run fine.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.