Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I would like the javascript to catch integers as a invalid input. Can that be done? 1 import java.util.Scanner; 3 public class Palindrome 4 args)

I would like the javascript to catch integers as a invalid input. Can that be done?

image text in transcribed

1 import java.util.Scanner; 3 public class Palindrome 4 args) i public static void main(String System.out.print("Enter a sentence or word to check"; Scanner reader new Scanner(System. in); String str = reader.next Line(); 10 boolean result-palindrome(str); 12 13 14 15 16 17 18 19 20 21 if(result) System.out.println(str" IS a palindrome!"; else i System.out.println(strIS NOT a palindrome!"); reader.closeO; 23 24 25 26 27 28 29 30 31 32 //Method used public static boolean palindrome(String str) String reverse ""; boolean resultfalse ""); String Str= str. replaceAll("[^a-zA-Z) ", Str = Str. toLowerCase(); int i Str.lengthO) -1; i -0; i--) reverse-reverse Str.charAt(i); for 34 35 36 37 38 if (Str.contentEquals(reverse))[ result true; } else [ 39 40 41 42 43 resultfalse; return result

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

Write short notes on Interviews.

Answered: 1 week ago