Java String Reverse

  • + 1 comment

    (i wrote this program and i don't knw, what the problem is, but it is running properly with the correct output and hacker rank is giving some test case errors) import java.io.; import java.util.;

    public class Solution { public static boolean isPalindrome(String str){ str = str.replaceAll("\s", "").toLowerCase(); int left = 0; int right = str.length()-1;

        while(left < right){
            if (str.charAt(left) != str.charAt(right)) {
                return false;
            }
            left++;
            right--;
        }
        return true;
    
    
    
    }
    
    public static void main(String[] args) {
    
        Scanner sc=new Scanner(System.in);
        String A=sc.nextLine();
    
        if(isPalindrome(A)){
            System.out.println("yes");
        }
        else{
            System.out.println("no");
        }
    
    
    }
    

    }