Skip to content

Instantly share code, notes, and snippets.

@frg
Created December 17, 2011 14:17
Show Gist options
  • Save frg/1490313 to your computer and use it in GitHub Desktop.
Save frg/1490313 to your computer and use it in GitHub Desktop.
Debugging chris's PalindromeCheck code.
import javax.swing.JOptionPane;
import java.lang.String;
public class PalindromeCheck
{
public static void main(String[]args)
{
String terminate = "exit";
String wordOne = "";
boolean exit = false;
do
{
wordOne =JOptionPane.showInputDialog(null,"Please Enter A Word/Phrase","INPUT",JOptionPane.QUESTION_MESSAGE);
if (terminate.equalsIgnoreCase(wordOne))
{
exit = true;
}
if ((wordOne!="") && (exit == false))
{
String wordTwo = wordOne;
StringBuffer wordRev = new StringBuffer(wordTwo);
if(wordOne.equalsIgnoreCase(wordRev.reverse().toString()))
{
JOptionPane.showMessageDialog(null, wordOne+ " IS A PALINDROME");
}
else
{
JOptionPane.showMessageDialog(null, wordOne+ " IS NOT A PALINDROME");
}
}
} while(exit == false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment