用C#写了一个求阶乘的程序,但是无法运行,大家帮个忙,谢谢!

[复制链接]
查看11 | 回复2 | 2011-3-9 17:58:42 | 显示全部楼层 |阅读模式
public class factorial

{

internal int num;

internal int result=1;

public static void factor()

{

Console.WriteLine("请输入一个数用来求阶乘:");

num=Console.Read();

if (num<=0)

Console.WriteLine("输入值不合法!");

return;

else

for (int j=1;j<=num;j++)

{

result*=j;

}

Console.WriteLine("{0}",result);

}

}

public class program

{

factorial aa=new factorial();

aa.factor();

}

回复

使用道具 举报

千问 | 2011-3-9 17:58:42 | 显示全部楼层
//第一.把调用写在主函数里;public class program
{
public static void Main(String []args)
{
factorial aa=new factorial();
aa.factor();
}
}
回复

使用道具 举报

千问 | 2011-3-9 17:58:42 | 显示全部楼层
if (num<=0)
Console.WriteLine("输入值不合法!");
return;改成 if (num<=0){
Console.WriteLine("输入值不合法!");
return;}把大括号漏了,直接返回了~
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行