0

Why it always print yes

import java.util.Scanner; public class Javac { public static void main(String[] args) { System.out.println("Enter a sring"); Scanner sc= new Scanner(System.in); String s=sc.nextLine(); check(s); } static void check(String s) { int end = s.length()-1; int start=0; boolean ans=true; while(start<end) { if(s.charAt(start)!=s.charAt(end)) { ans=false; break; } start++; end--; } if(ans=true) { System.out.println("yes"); } else { System.out.println("no"); } } } /* INPUT : SACHIN OUTPUT : YES PALINDROME CHECK */

19th Apr 2021, 12:29 PM
Sachin Saxena
Sachin Saxena - avatar
2 ответов
+ 3
Look at this line if(ans==true) { One '=' is missing
19th Apr 2021, 12:36 PM
Coding Cat
Coding Cat - avatar
+ 1
Than you it takes my 3 hrs
20th Apr 2021, 4:16 PM
Sachin Saxena
Sachin Saxena - avatar