PalindromeTester - return converted Tests strings to see if...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // PalindromeTester.java Author: Lewis/Loftus // // Solution to Programming Project 5.9 //******************************************************************** / import javax.swing.JOptionPane; i public class PalindromeTester { //----------------------------------------------------------------- // Removes whitespace and punction from a string. Converts all // characters to lowercase. //----------------------------------------------------------------- private static String convertString(String s) { String converted = ""; char current; for (int i=0; i<s.length(); i++) { current = s.charAt(i); if (Character.isLetterOrDigit(current)) // only count letters and digits { if (Character.isUpperCase(current)) // convert to lowercase if needed current = Character.toLowerCase(current); converted += current;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } } return converted; } //-----------------------------------------------------------------// Tests strings to see if they are palindromes. //-----------------------------------------------------------------public static void main (String args) { String str, result, in; int left, right; int another; do { in = JOptionPane.showInputDialog ("Enter a potential palindrome:"); str = convertString(in); left = 0; right = str.length() - 1; while (str.charAt(left) == str.charAt(right) && left < right) { left++; right--; } result = "\"" + in + "\""; if (left < right) result += " is NOT a palindrome."; else result += " IS a palindrome."; JOptionPane.showMessageDialog(null, result); another = JOptionPane.showConfirmDialog(null,"Test another palindrome? "); } while (another == JOptionPane.YES_OPTION); } }...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

PalindromeTester - return converted Tests strings to see if...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online