SHARE
TWEET

Palindrome

X4c3 Nov 19th, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Palindrome {
  4.  
  5.     public static void main(String args[]){
  6.  
  7.         int repeat = 1;
  8.         while (repeat == 1){
  9.  
  10.         String myString, data;
  11.         StringBuilder builder;
  12.         Scanner sc = new Scanner (System.in);
  13.  
  14.         System.out.println("Input a string: ");
  15.         myString = sc.nextLine();
  16.  
  17.             builder = new StringBuilder(myString);
  18.             builder.reverse();
  19.             data = builder.toString();
  20.  
  21.             if (myString.equals(data)){
  22.                 System.out.println("Given String "+myString+" is palindrome");
  23.                 System.out.println("To run again input '1', to exit input any number");
  24.                 repeat = sc.nextInt();
  25.             }
  26.             else {
  27.                 System.out.println("Given String " + myString + " is not palindrome");
  28.                 System.out.println("To run again input '1', to exit input any number");
  29.                 repeat = sc.nextInt();
  30.             }
  31.         }
  32.     }
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top