All pastes #464517 Raw Edit

Miscellany

public java v1 · immutable
#464517 ·published 2007-04-29 15:46 UTC
rendered paste body
public class Palindrome {	private static String stripWhitespace(String arg) {		String newstr = "";		for (char c : arg.toCharArray())			if (Character.isLetter(c))				newstr = newstr + c;				return newstr;	}		private static String reverseString(String arg) {		StringBuilder sb = new StringBuilder(arg);		sb.reverse();		return sb.toString();	}		public static boolean isPalindrome(String arg) {		String cleanarg = stripWhitespace(arg);		int cleanlen = cleanarg.length();		int halfpt = (int)Math.floor(((double)cleanlen)/2);		String a = cleanarg.substring(0, halfpt);		String b = cleanarg.substring(halfpt);				// reverse and truncate other half		b = reverseString(b);		b = b.substring(0, halfpt);		// check		return a.equalsIgnoreCase(b);			}		/**	 * @param args	 */	public static void main(String[] args) {		String[] checks = {				"Glenelg", "Stupid Idiot", "Complex elPmoc", "Campus Motto: Bottos up, Mac",				"Another rehToNa"		};				for (String s : checks) {			System.out.println("String (" + s + "): " + isPalindrome(s));		}	}}