java`````

woaiac 2006-12-24 02:36:39
import java.io.*;
import java.util.Scanner;
public class Q
{
public int Jisuan(m)
{
if(m==0)
{
return 1;
}
else
{
return 2*Jisuan(m-1);
}
}
public static void main(String[] agrs)
{ int j,res;
System.out.println("please input a digital to calculate the answer of :");
Scanner n=new Scanner(System.in);
j=n.next();
Q a=new Q();
res=a.Jisuan(j);
System.out.println("the result is:"+res);

}
}




这是计算2的n次方的程序 递归算法```  我修改了好久还是没完成 到底问题出现在哪里啊???出现下面两个错误 什么意思啊
   <idetifier>excepted
')'excepted
...全文
122 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wddodo 2006-12-25
  • 打赏
  • 举报
回复
public int Jisuan(m)
{
if(m==0)
{
return 1;
}
else
{
return 2*Jisuan(m-1);
}
}

这个函数的参数怎么没有类型?改为
public int Jisuan(int m)
{
if(m==0)
{
return 1;
}
else
{
return 2*Jisuan(m-1);
}
}
zdywqy 2006-12-25
  • 打赏
  • 举报
回复
jf
jk88811 2006-12-24
  • 打赏
  • 举报
回复
import java.io.*;
import java.util.Scanner;

public class Power
{
public int cal(int m) // 少了int
{
if(m==0)
{
return 1;
}
else
{
return 2*cal(m-1);
}
}
public static void main(String[] agrs)
{
int j,res;
System.out.println("please input a digital to calculate the answer of :");
Scanner n=new Scanner(System.in);
j=n.nextInt(); // 使用nextInt()读取下一个整数
Power a=new Power();
res=a.cal(j);
System.out.println("the result is:"+res);
}
}

随便改了下, 楼主注意写程序的时候尽量使用些好点儿的名字, 别用什么P, Q啊。。。

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧