Write a java program to checks whether a given string is a palindrome or not


Write a java program to checks whether a given string is a palindrome or not 

Week 3

b)Aim: To Write a Java program that checks whether a given string is a palindrome or not. Ex: MADAM is a Palindrome.

 
Source Code:
import java.util.*;
 
class Palind
{
   public static void main(String args[])
   {
      String original, reverse=””;
      Scanner in = new Scanner(System.in);
 
      System.out.println(“Enter a string to check if it is a palindrome”);
      original = in.nextLine();
 
      int length = original.length();
 
      for ( int i = length – 1 ; i >= 0 ; i– )
         reverse = reverse + original.charAt(i);
 
      if (original.equals(reverse))
         System.out.println(“Entered string is a palindrome.”);
      else
         System.out.println(“Entered string is not a palindrome.”);
 
   }
}
 
Expected Output:
 
Enter a string to check if it is a palindrome
Madam
Entered string is a palindrome
Write a java program to Checks whether a given string is a palindrome or not

Write a java program to checks whether a given string is a palindrome or not

https://en.wikipedia.org/wiki/Palindromic_number

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories