Check string for palindrome

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

    Here you can check palindrome a number of String dynamically

    import java.util.Scanner;
    
    public class Checkpalindrome {
     public static void main(String args[]) {
      String original, reverse = "";
      Scanner in = new Scanner(System.in);
      System.out.println("Enter How Many number of Input you want : ");
      int numOfInt = in.nextInt();
      original = in.nextLine();
    do {
      if (numOfInt == 0) {
        System.out.println("Your Input Conplete");
       } 
      else {
        System.out.println("Enter a string to check palindrome");
        original = in.nextLine();
    
        StringBuffer buffer = new StringBuffer(original);
        reverse = buffer.reverse().toString();
    
      if (original.equalsIgnoreCase(reverse)) {
        System.out.println("The entered string is Palindrome:"+reverse);
       } 
      else {
        System.out.println("The entered string is not Palindrome:"+reverse);
        }
     }
       numOfInt--;
        } while (numOfInt >= 0);
    }
    }
    

提交回复
热议问题