Question: Palindrome.java please finish the code below rules 1. Read in the string and convert it to all lower case using toLowerCase() 2. Remove any character
Palindrome.java
please finish the code below
rules
1. Read in the string and convert it to all lower case using toLowerCase()
2. Remove any character which is neither a letter nor a digit; you can use Character.isDigit(...) and Character.isLetter(...) to test for this. All punctuation and
white space will be remove. (Hint: use replace(....) to replace any non-letter non-digit by the empty String ).
3. Using charAt(...) check if the word is a palindrome by checking if each letter is the same as the letter in its mirror image position; for example Taco Cat and Toot! are palindromes:
import java.util.Scanner; public class Palindrome { /* * TODO: Complete this method as per the requirements of the assignment handout. * Make sure not to change the function signature. */ public static boolean isPalindrome( String line ) { /*We are providing you with a list of punctuations that we will use to test your code. * make sure that you use this same list of punctuations only and not something else. */ char[] punctuation = { '.', ',', ';', ':', '?', '/', '\'', '\'', '!', '-', '~', '(', ')' }; } /* * DO NOT MODIFY THE MAIN FUNCTION. * ANY CODE THAT YOU WRITE, MUST BE * INSIDE THE isPalindrome function. * Any code that you write inside the main * function will not be marked and will be completely ignored. */ public static void main(String[] args) { // Print out welcome message System.out.println(" Welcome to the Palindrome Test Program!"); // Define a scanner for user input Scanner userInput = new Scanner(System.in); System.out.println(" Type in a sentence to be tested or Control-d to end:"); while (userInput.hasNextLine()) { String line = userInput.nextLine(); if(isPalindrome( line )) System.out.println("Palindrome!"); else System.out.println("Not a palindrome!"); } System.out.println("bye!"); } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
