Palindrome

Palindrome - System.out.println("Please enter...

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

View Full Document Right Arrow Icon
import java.util.Scanner; /* * Name:Xin Chi * Section:004 * Program 6 - Palindrome * * Implementation Plan * 1. Copy the skeleton. * 2. Print message. * 3. Read input from user. * 4. Write a loop. * 5. Determine the input string is palindrome or not and print it. * 6. Write a loop to keep processing this program until the user types "done". * Test Plan * Input output * Typical case * rats live on no evil star yes * * Boundary Conditions * ab sdfw dfw no * a,b. s d fw. dfw no * nev er odd or e ven yes * dennis sinned yes * d,e.nn''is s,.inne.'d yes * .aba,' yes * done N/A * */ public class Palindrome { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in);
Background image of page 1

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

View Full DocumentRight 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: System.out.println("Please enter a possible palindrome"); String s = keyboard.nextLine(); do { int l = 0; int r = s.length() - 1; while (l < r) { if (s.charAt(l) == s.charAt(r)) { l++; r--; } else if (s.charAt(l) == ',' || s.charAt(l) == '.' || s.charAt(l) == '\'' || s.charAt(l) == ' ') l++; else if (s.charAt(r) == ',' || s.charAt(r) == '.' || s.charAt(r) == '\'' || s.charAt(r) == ' ') r--; else break; } boolean isnotpalindrome = (l < r); if (isnotpalindrome) { System.out.println("no"); } else System.out.println("yes"); System.out.println(); s = keyboard.nextLine(); } while (!s.equalsIgnoreCase("done")); } }...
View Full Document

This note was uploaded on 06/10/2011 for the course COMP 110 taught by Professor Stotts during the Fall '08 term at UNC.

Page1 / 2

Palindrome - System.out.println("Please enter...

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