Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I wrote a code to test if the inputted string is a palindrome, but I need to remove the caps, spacing, and punctuation. I can't
I wrote a code to test if the inputted string is a palindrome, but I need to remove the caps, spacing, and punctuation. I can't seem to figure out how to make my code work.
import java.util.Scanner; class Palindromef public static void main (String args[1)f Scanner kb - new Scanner (System.in); System.out.print ("Enter a word or sentence:") String line - kb.nextLine () isReverse (line); public static boolean isReverse (String line) string newLine = '' '' ; String reve r seLine '' '' ; line = line. toLowerCase() ; for (int i = 0; i = 11ne.length() - I; i++ if (Character.isLetter(line.charAt (i))) newLine += line . charAt (i) ; for (int 1-newLine . length ( )-1; i-0; i--) reverseLine += newLine . charAt (i); if (line.equals (reverseLine)) System.out.println(" Input string is a palindrome."); return true else System.out.println ("Input string is not a palindrome."); return false
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started