Check string for palindrome

前端 未结 30 3178
悲哀的现实
悲哀的现实 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:22

    Try this out :

    import java.util.*;
        public class str {
    
            public static void main(String args[])
            {
              Scanner in=new Scanner(System.in);
              System.out.println("ENTER YOUR STRING: ");
              String a=in.nextLine();
              System.out.println("GIVEN STRING IS: "+a);
              StringBuffer str=new StringBuffer(a);
              StringBuffer str2=new StringBuffer(str.reverse());
              String s2=new String(str2);
              System.out.println("THE REVERSED STRING IS: "+str2);
                if(a.equals(s2))    
                    System.out.println("ITS A PALINDROME");
                else
                    System.out.println("ITS NOT A PALINDROME");
                }
        }
    

提交回复
热议问题