SixPalindrome - String first = buffer.substring(0,...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.io.PrintStream; i public class SixPalindrome { public static void main(String[] args) { PrintStream out = System.out; String buffer = args[0]; out.printf("%s ", buffer); final String INVERSE = "[^a-z]"; buffer = buffer.toLowerCase().replaceAll(INVERSE, ""); final int LENGTH = buffer.length(); int firstPivot = LENGTH / 2, secondPivot = 0; secondPivot = LENGTH % 2 == 0 ? firstPivot : firstPivot + 1;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: String first = buffer.substring(0, firstPivot); String firstHalf = new StringBuffer(first).reverse().toString(); String second = buffer.substring(secondPivot, LENGTH); String secondHalf = new StringBuffer(second).toString(); if (firstHalf.equals(secondHalf)) { out.printf("is a palindrome!%n");; } else { out.printf("not a palindrome!%n"); } } }...
View Full Document

This note was uploaded on 09/16/2011 for the course CSE CSE 1020 taught by Professor Burton,ma during the Fall '10 term at York University.

Ask a homework question - tutors are online