Wednesday 25 July 2018

What is Palindrome and Write a program in java to find a String is Palindrome or Not

   What is Palindrome String and Write a program in java to find String is Palindrome or Not



palindrome string is a string that reads the same backward as forward and can be of odd or even length. A palindrome number is a number which is equal to its reverse. Our program works as follows: at first, we copy the entered string into a new string, and then we reverse and compare it with originalstring.


Algo of palindrome program


isPalindrome(str)
1) Find length of str. Let length be n.
2) Initialize low and high indexes as 0 and n-1 respectively.
3) Do following while low index ‘l’ is smaller than high index ‘h’.
…..a) If str[l] is not same as str[h], then return false.
…..b) Increment l and decrement h, i.e., do l++ and h–.
4) If we reach here, it means we didn’t find a mis


import java.util.*;

class Palindrome
{
   public static void main(String args[])
   {
      String original, reverse = ""; // Objects of String class
      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 isn't a palindrome.");

   }
}


😍Developer on Weekends #shorts #officememes #developermemes

😍Developer on Weekends #shorts #officememes #developermemes Welcome to the latest viral YouTube shorts meme for developers! 😍Developer on...