Java String Reverse

  • + 0 comments

    Solution :-

    1. First you should convert the string to its reversed order.
    2. Then compare both the strings.
    3. If the result is true, print Yes esle print No.
    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();
            String s = "";
            /* Enter your code here. Print output to STDOUT. */
            for (int i = A.length() - 1; i >= 0; i--) {
                s += A.charAt(i);
            }
            if(A.equals(s)){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }
    }