Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Palindrome
- {
- public static void main(String[] args)
- {
- String word,reverse, same;
- word = phrase();
- reverse = flip(word);
- match(word, reverse);
- }
- public static String phrase()
- {
- String word;
- Scanner keyboard = new Scanner(System.in);
- System.out.println("Please enter a word: ");
- word = keyboard.nextLine();
- return word;
- }
- public static String flip(String sentence)
- {
- String reverse;
- reverse = "";
- int length = sentence.length();
- for(int i = length - 1; i >= 0; i--)
- {
- reverse = reverse + sentence.charAt(i);
- }
- return reverse;
- }
- public static void match(String original, String backward)
- {
- if(original.equalsIgnoreCase(backward))
- {
- System.out.println("\" " + original + " \" is a palindrome");
- }
- else
- {
- System.out.println("\" " + original + " \" is not a palindrome");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement