Why it always print yes | Sololearn: Learn to code for FREE!

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 */

4/19/2021 12:29:04 PM

Sachin Saxena

2 Answers

New Answer

+3

Look at this line if(ans==true) { One '=' is missing

+1

Than you it takes my 3 hrs