正文

判断回文数2007-09-26 10:07:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/tld5yj/29668.html

分享到:

Java中实现的对输入的字符串判断是否回文数的程序,保存在文本文档里,并把文档更名为huiwen.java,命令提示符下运行即可。 public class huiwen {public static void main(String arg[]) throws java.io.IOException {char s[]=new char[20];  int i=-1,count;  System.out.println("请输入要判断的串:");  do  {i++;   s[i]=(char)System.in.read();  }while(s[i]!='\n');  count=i;  for(i=0;i<count-2-i;i++)  {if(s[i]!=s[count-2-i])break;  }  if(i<(count-2-i))System.out.println("这不是回文数。");  else System.out.println("这是回文数。"); }}

阅读(4147) | 评论(1)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册