Java中的字符串回文

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
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

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值