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 */
2 Réponses
+ 3
Look at this line
if(ans==true) {
One '=' is missing
+ 1
Than you it takes my 3 hrs