Advertisement
DulcetAirman

palindrome with StringBuffer

Apr 21st, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement