Палиндром – это не что иное, как любое число или строка, которая остается неизменной, когда она перевернута. Например: 121 или RAR . Заметно, что форма букв отражает изображения на обороте.
class PalindromeProgramInJavaForReversingString{ public static void checkPalindrome(String s){ // Reversing given string using StringBuffer class String reverse = new StringBuffer(s).reverse().toString(); // checks whether the string is palindrome or not if (s.equals(reverse)){ System.out.println("Yes, it is a palindrome"); }else{ System.out.println("No, it is not a palindrome"); } } public static void main (String[] args)throws java.lang.Exception{ checkPalindrome("madam"); } }
Узнайте больше о Палиндроме :
Оригинал: “https://dev.to/rajesh1761/palindrome-program-in-java-for-reversing-string-4a1c”