Java String Palindrome Program: Java Coding Interview Question 1 #programming #job #spring #tutorial

Javaプログラム

This is one of the most common Java interview questions: Write a Java String Palindrome Checker using RegEx, Strings, the StringBuilder class and conditional logic. And do it all on the JDK and make it all run in a Java main method.

Can you do it? Are you up to the task?

Watch this video for a hint, and then put this video away and code this Java Palindrome Checker for Strings on your own. I know you can do it!

**************

One of the most common, practical programming questions developers encounter on interviews is ‘how to write a palindrome checker?”

A palindrome is a word or phrase that reads the same forwards and backwards, like “racecar” or “madam”.

It takes a bit of thought, but with some creative use of Regex, conditionals and the String Builder class, it’s an easy row to hoe.

First, we take an input string and remove any spaces or special characters. That’s where the Regex comes in.

Then, we reverse the string. That’s where the StringBuilder comes in.

And then we compare the original String to the reversed String.

If both are the same, it’s a palindrome!

Were you looking for some code? Well here it is:

コメント

タイトルとURLをコピーしました