4的5次方用递归编程
来源:百度知道 编辑:UC知道 时间:2024/05/03 11:07:07
我编了但是编错了
请帮忙修改
Class Fa
int fact(int n){
int result
if (n==0){
return 1;
}
else
{
return=fact(n-1)*4;
return result
}
}
{
public class Fact{
public static void main(String argc[])
{Fa()=new Fa();
system.out.println("4的5次方");
}
}
我照老师抄的,能不能给出个完整的能运行的谢谢
用递归调用。
一楼的自己提问好吗?
四楼的能不能再改一下,名字不对
请帮忙修改
Class Fa
int fact(int n){
int result
if (n==0){
return 1;
}
else
{
return=fact(n-1)*4;
return result
}
}
{
public class Fact{
public static void main(String argc[])
{Fa()=new Fa();
system.out.println("4的5次方");
}
}
我照老师抄的,能不能给出个完整的能运行的谢谢
用递归调用。
一楼的自己提问好吗?
四楼的能不能再改一下,名字不对
public class jc {
public static void main(String[] args) {
fun f = new fun();
int sum = f.fun(5);
System.out.println(sum);
}
}
public class fun {
public int fun(int n){
int sum = 0;
if(n!=0){
sum = fun(n-1)*4;
}else{
sum = 1;
}
return sum;
}
}
对不起,我不会,另外老兄,能告诉我你的JAVA编辑器是在哪里下的吗?能不能给我个下载地址啊,谢谢了,我也在学习这个
public static void main(String argc[])
{Fa()=new Fa();
system.out.println("4的5次方");
}
//改为
public static void main(String args[])
{Fa fa = new Fa();
int x = fa.fact(5);
System.out.println("4的5次方" + x);
}
我不知道你是怎么写的,"{"和"}"都不配对,哪们可能不错嘛!
return=fact(n-1)*4;
return result //不能两个return同时出现在else句段里
Fa()=new Fa(); //Fa()这个括号你怎么可以用中文的括号 呢,更何况用了括号也是错的。这一句应该 为: