SHARE
TWEET

palindrome with StringBuffer

DulcetAirman Apr 21st, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ch.claude_martin;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SomeClass {
  6.     public static void main(String args[]) throws ClassNotFoundException {
  7.         try (var kb = new Scanner(System.in)) {
  8.             while (true) {
  9.                 System.out.println("input a word and hit enter (type 'exit' to exit)");
  10.                 var word = kb.nextLine();
  11.                 if ("exit".equals(word))
  12.                     break;
  13.                 var word2 = new StringBuffer(word).reverse().toString();
  14.                 if (word.equals(word2))
  15.                     System.out.format("The word '%s' is a palindrome%n", word);
  16.                 else
  17.                     System.out.format("The reverse of '%s' is '%s'%n", word, word2);
  18.             }
  19.             System.out.println("good bye");
  20.         }
  21.     }
  22. }
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
 
Top