using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 回文数
{
class Program
{
public void tongji()
{int j=0;
for(double i=11111;i<=99999;i++){
double a = i / 10000;
double b = i % 10000 / 1000;
double c = i % 100 / 10;
double d = i % 10;
if (d==a&&c==b)
j++;
}
Console.WriteLine("五位回文数的个数:{0}", j);
}
static void Main(string[] args)
{
Console.WriteLine("1.判断回文数");
Console.WriteLine("2.统计五位回文数");
string k = Console.ReadKey().Key.ToString();
Console.Clear();
switch (k)
{
case "D1":
Console.Write("请输入一个五位整数:");
var x = Convert.ToInt32(Console.ReadLine());
var wan = x / 10000;
var qian = x % 10000 / 1000;
var shi = x % 100 / 10;
var ge = x % 10;
if (ge == wan && shi == qian)
Console.WriteLine("{0},这个数是回文数", x);
else
Console.WriteLine("{0},这个数不是回文数", x);
break;
case "D2": Program a1 = new Program();
a1.tongji();
break;
}
}
}
}
方法tongji()做出来答案为0,谁能帮我改下
请参考:
PS :以上代码在vs2008中测试通过,你可以在任意可调用StrEx类的地方使用上面的字符串扩展方法,如:
"字符串实例".IsPalindrome()
int a;a.ToString().IsPalindrome()
去判断是否回文!