Here you will get program for string palindrome in java.
在这里,您将获得Java中字符串回文的程序。
Palindrome: asdsa, madam, mom, etc.
回文:asdsa,女士,妈妈等
Below I have shared a program that will check a string is palindrome in java or not. In this program I am reversing the string and then comparing the reversed string with original string. I have used Scanner class to read the string from keyboard. If you find any difficulty to understand the program then you can ask your queries in the comment section.
下面我共享了一个程序,该程序将检查字符串是否在Java中是回文 。 在此程序中,我将反转字符串,然后将反转的字符串与原始字符串进行比较。 我已经使用Scanner类从键盘读取字符串。 如果您在理解程序方面遇到任何困难,则可以在评论部分提出疑问。
Java中的字符串回文 (String Palindrome in Java)
import java.util.Scanner;
class StringPalindrome
{
public static void main(String...s)
{
String str1="",str2="";
Scanner sc=new Scanner(System.in);
System.out.println("Enter a string:");
str1=sc.nextLine();
for(int i=str1.length()-1;i>=0;--i)
str2=str2+str1.charAt(i);
if(str1.equals(str2))
System.out.println("String is Palindrome");
else
System.out.println("String is Not Palindrome");
}
}
Output
输出量
![String Palindrome Program in Java String Palindrome Program in Java](https://4.bp.blogspot.com/-gfsvvPRTrc8/VTj_0bwK2UI/AAAAAAAAEWs/VLqbmfQ9384/s1600/String%2BPalindrome%2BProgram%2Bin%2BJava.jpg)
If you found any mistake in above program for string palindrome in java then please mention it by commenting below.
如果您在上述程序中在Java中发现了字符串回文错误,请在下面的注释中提及。
翻译自: https://www.thecrazyprogrammer.com/2015/04/string-palindrome-program-in-java.html