Palindrome assignment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • colinNeedsJavaHelp
    New Member
    • Feb 2007
    • 22

    Palindrome assignment

    I am still having an exceptional amount of trouble with java. This is my new assignment, if anyone can help I would greatly appreciate it. I don't even know where to start.

    A word or phrase in which the letters spell the same message when written forward and backward (with whitespaces and punctuations not considered) is called a palindrome.

    Write a simple Java program that detects palindromes. Your program should be named "PalindromeDete ctor.java", and the class in it should be named "PalindromeDete ctor".

    The program should first ask for the input text:
    Input text? user input

    If the entered text is a palindrome, display the message:
    This is a palindrome.

    Otherwise display:
    This is not a palindrome.

    Notice that whitespaces and punctuations not considered; cases of characters don't matter, either. Thus the strings "ab, a " and "Was it a cat I saw?" are both palindromes. You can assume that the user input only possibly includes the following four punctuation marks:
    , . ! ?
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by colinNeedsJavaH elp
    I am still having an exceptional amount of trouble with java. This is my new assignment, if anyone can help I would greatly appreciate it. I don't even know where to start.

    A word or phrase in which the letters spell the same message when written forward and backward (with whitespaces and punctuations not considered) is called a palindrome.

    Write a simple Java program that detects palindromes. Your program should be named "PalindromeDete ctor.java", and the class in it should be named "PalindromeDete ctor".

    The program should first ask for the input text:
    Input text? user input

    If the entered text is a palindrome, display the message:
    This is a palindrome.

    Otherwise display:
    This is not a palindrome.

    Notice that whitespaces and punctuations not considered; cases of characters don't matter, either. Thus the strings "ab, a " and "Was it a cat I saw?" are both palindromes. You can assume that the user input only possibly includes the following four punctuation marks:
    , . ! ?
    Colin, go back to your teacher and explain to him your problems with the assignment. Once you get to understand the assignment better, you can come back with some code written and we can help from there.

    Comment

    • colinNeedsJavaHelp
      New Member
      • Feb 2007
      • 22

      #3
      ok so this is what I have for the code so far:

      Code:
      import java.io.*;
      import java.util.*;
      public class PalTest
        {
         public static void main(String[] args)
         throws java.io.IOException   
        {
         String inputString;
         StringBuffer S;
      
         InputStreamReader isr = new InputStreamReader(System.in);
         
         BufferedReader br = new BufferedReader(isr);
        
         System.out.println("Input Text? ");
         inputString  = br.readLine();
       
         S = new StringBuffer(inputString);
         S.reverse();
      
         if (inputString.equalsIgnoreCase(S.toString())) {
         System.out.println("This is a palindrome.");
        }
        else {
        System.out.println("This is not a palindrome.");
      }
      }
      }
      My only problem now is getting it to accept the punctuations , . ! ?

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by colinNeedsJavaH elp
        ok so this is what I have for the code so far:

        Code:
        import java.io.*;
        import java.util.*;
        public class PalTest
        {
        public static void main(String[] args)
        throws java.io.IOException 
        {
        String inputString;
        StringBuffer S;
         
        InputStreamReader isr = new InputStreamReader(System.in);
         
        BufferedReader br = new BufferedReader(isr);
         
        System.out.println("Input Text? ");
        inputString = br.readLine();
         
        S = new StringBuffer(inputString);
        S.reverse();
         
        if (inputString.equalsIgnoreCase(S.toString())) {
        System.out.println("This is a palindrome.");
        }
        else {
        System.out.println("This is not a palindrome.");
        }
        }
        }
        My only problem now is getting it to accept the punctuations , . ! ?
        What problems are you getting with the punctuation?

        Comment

        Working...