Wednesday, July 26, 2023

Java String Reverse

 A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward.


Given a string , print Yes if it is a palindrome, print No otherwise.

Constraints

  •  will consist at most  lower case english letters.

Sample Input

madam

Sample Output

Yes

SOLUTION:
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 B="";
        char ch;
        for (int i=0; i<A.length(); i++)
      {
        ch= A.charAt(i); 
        B= ch+B;
      }
        if(A.equals(B))
        {
            System.out.println("Yes");
        }
        else
         System.out.println("No");
    }
}

No comments:

Post a Comment

Featured Post

14. Longest Common Prefix

Popular Posts