Java String Reverse

  • + 0 comments

    I believe inorder to check palindrome we need to check the word is same from backward to forward. For this i reverse the word by every char and concat to new String and check for Equal value of both String objects.

    import java.io.; import java.util.;

    public class Solution {

    public static void main(String[] args) {
    
        Scanner sc=new Scanner(System.in);
        String A=sc.next();
        /* Enter your code here. Print output to STDOUT. */
        String k ="";
        for(int i =A.length()-1;i>=0;i--){
            char c = A.charAt(i);
            String ch = Character.toString(c);
            k = k.concat(ch);
        }
        if(A.equals(k))
        {
            System.out.println("Yes");
        }
        else 
            System.out.println("No");
    
    }
    

    }