It is showing tle, what am i doing wrong?

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);

	String str=sc.nextLine();
	int a=1;
	int low=0;
	int high=str.length()-1;
	if(str.length()==0 || str.length()==1){
		System.out.println("true");
	}
	else{
		while(low<high){
			if(str.charAt(low)==str.charAt(high)){
				low++;
				high--;
			}
			else{
				a=0;
			}
		}
		if(a==0){
			System.out.println("false");
		}
		else{
			System.out.println("true");
		}
	}
}

}

@laibaahsan27_1dfa992390072fd9 You should break the loop when str.charAt(low)==str.charAt(high) comes out to be false because your else condition makes a = 0; but since it is not updating low and high so the loop will continue for infinite times. so just add a break statement after you make a = 0; like this :

if(str.charAt(low)==str.charAt(high)){
				low++;
				high--;
			}
			else{
				a=0;
				//added break statement here
				break;
			}

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.