Palindrome Detector

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

No — that is one of the advantages of using StringBuffer.

Palindrome Detector

A palindrome is a string that reads the same when it is reversed. Punctuation, spaces, and capitalization are ignored. For example, the following is a palindrome:

A man, a plan, a canal, Panama!

Let us write a program that determines if a string is a palindrome. In this program, the string is hard-coded in the program as a String object.

class Tester
{
  public boolean test( String trial )
  {
    . . . .
  }
}

public class PalindromeTester
{
  public static void main ( String[] args )
  {
    Tester pTester = new Tester();
    String trial = "A man, a plan, a canal, Panama!" ;
    if ( pTester.test( trial ) )
      System.out.println( "Is a Palindrome" );
    else
      System.out.println( "Not a Palindrome" );
  }
}

QUESTION 9:

Class String has a method toLowerCase() and a method toUpperCase(). Will these methods be useful?