Home > Java > javaTutorial > body text

How to check if a string is a palindrome in Jshell in Java 9?

WBOY
Release: 2023-08-27 13:33:06
forward
1218 people have browsed it

如何在Java 9的Jshell中检查一个字符串是否是回文?

JShell is the first REPL (read-evaluate-print-loop) interactive tool, as ## Part of # introduced in >Java 9. It evaluates the entered declarations , statements and expressions and displays the results immediately, and from the command line prompt.

Palindrome StringA string is a string that remains unchanged when turned upside down or when words are spelled the same in forward and backward directions. p>In the following example, we can check if the given string is a palindrome in JShell tool.

<strong>C:\Users\User>jshell
| Welcome to JShell -- Version 9.0.4
| For an introduction type: /help intro

jshell> String str="LEVEL";
str ==> "LEVEL"

jshell> String revstring="";
revstring ==> ""

jshell> {
...>       for(int i=str.length()-1; i>=0; --i) {
...>          revstring +=str.charAt(i);
...>       }
...>       System.out.println(revstring);
...>       if(revstring.equalsIgnoreCase(str)){
...>          System.out.println("String is Palindrome");
...>       } else {
...>          System.out.println("String is not Palindrome");
...>       }
...>    }
LEVEL
String is Palindrome
</strong>
Copy after login

The above is the detailed content of How to check if a string is a palindrome in Jshell in Java 9?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!