class Class1
{
public static bool abc(int a)
{
bool x = true;
for (int i = 2; i < a; i++)
{
if (a % i == 0) x = (!true);
}
return x;
}
[STAThread]
static void Main(string[] args)
{
//string p;
bool aa = true;
while (aa)
{
Console.WriteLine("请输入一个大于2的整数:");
string p = Console.ReadLine();
try
{
//FileClose();
int e = int.Parse(p);
if (abc(e)) Console.WriteLine("你输入的数是素数!");
else Console.WriteLine("你输入的数不是素数!");
Console.WriteLine("是否继续输入数(y/n)");
char xx = (char)Console.ReadKey().KeyChar ;
if (xx == 'n' ¦ ¦ xx == 'N') aa = (!true);
Console.WriteLine(); //为了好看,无实际意义
}
catch (System.Exception E)
{
Console.WriteLine("你输入的数据数型错误!" + E);
Console.WriteLine(p);
aa = (!true);
}
}
}
}
{
public static bool abc(int a)
{
bool x = true;
for (int i = 2; i < a; i++)
{
if (a % i == 0) x = (!true);
}
return x;
}
[STAThread]
static void Main(string[] args)
{
//string p;
bool aa = true;
while (aa)
{
Console.WriteLine("请输入一个大于2的整数:");
string p = Console.ReadLine();
try
{
//FileClose();
int e = int.Parse(p);
if (abc(e)) Console.WriteLine("你输入的数是素数!");
else Console.WriteLine("你输入的数不是素数!");
Console.WriteLine("是否继续输入数(y/n)");
char xx = (char)Console.ReadKey().KeyChar ;
if (xx == 'n' ¦ ¦ xx == 'N') aa = (!true);
Console.WriteLine(); //为了好看,无实际意义
}
catch (System.Exception E)
{
Console.WriteLine("你输入的数据数型错误!" + E);
Console.WriteLine(p);
aa = (!true);
}
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货