Check string for palindrome

前端 未结 30 3510
悲哀的现实
悲哀的现实 2020-11-22 02:47

A palindrome is a word, phrase, number or other sequence of units that can be read the same way in either direction.

To check whether a word is a palindrome I get th

30条回答
  •  孤城傲影
    2020-11-22 03:35

    public class palindrome {
    public static void main(String[] args) {
        StringBuffer strBuf1 = new StringBuffer("malayalam");
        StringBuffer strBuf2 = new StringBuffer("malayalam");
        strBuf2.reverse();
    
    
        System.out.println(strBuf2);
        System.out.println((strBuf1.toString()).equals(strBuf2.toString()));
        if ((strBuf1.toString()).equals(strBuf2.toString()))
            System.out.println("palindrome");
        else
            System.out.println("not a palindrome");
    }
    

    }

提交回复
热议问题