java 急!! 答案!!!

来源:百度知道 编辑:UC知道 时间:2024/06/07 20:21:48
该程序共包括2个类,一个类为Another,要求在其中定义方法mul实现s=10!,返回值为整型,public类为Test,其main方法输出10!的结果。

public class Another
{
public int mul(int s)
{
if(s=1)
return 1;
else return s*nul(s-1);//递归调用此方法
}
}
public Text
{
public void main(String[] args)
{
int num=new Another().mul(10);
System.out.println("10!是:"+num);
}
}

Another 类:
public class Another
{
public static int mul()
{
int temp=1;
for(int i=1;i<=10;i++)
{
temp=temp*i;
}
return temp;
}
}

AnotherTest类:
public class AnotherTest
{
public static void main(String[] args)
{
System.out.println("10!的结果是:"+Another.mul());
}
}

也要参加补考吗?