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

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

WBOY
WBOYforward
2023-08-27 13:33:061280browse

如何在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>

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete