In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how java judges that a string is symmetrical before and after. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
How to tell if a string is symmetrical?
What do you mean? It's like a string with a 90% discount before and after, it's symmetrical. It's like standing in front of the mirror and seeing a Yushu facing the wind and shyness of the moon.
Public class PalindromeString {public static void main (String [] args) {checkPalindromeString ("Silent King II"); checkPalindromeString ("Silent King II Silence");} private static void checkPalindromeString (String input) {boolean result = true; int length = input.length (); for (int I = 0; I < length / 2) ) {if (input.charAt (I)! = input.charAt (length-I-1)) {result = false; break;}} System.out.println (input + "is it symmetric? "+ result);}}
The output is as follows:
Is the Silence King symmetrical? False Silence Wang er er Wang Mo Shen symmetrical? True
Let's talk about my idea: to determine whether a string is symmetrical or not, it's easy to split it from the middle, compare the first character to the last character, and return false once you find the one that is not equal.
Pay attention to three points:
1) the subscript of the for loop starts at 0 and ends with length/2.
2) the subscript I and length-i-1 are symmetrical.
3) once false, break.
This is the end of this article on "how java determines that a string is symmetrical". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.