Ackerman
Ackerman
一 . 问题描述及分析

图1

二 . 代码实现
package other;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class bin_1
{
public static void main(String[] args) throws IOException
{
Ackerman myAckerman=new Ackerman(10, 2);
}
}
class Ackerman
{
int m;
int n;
int result;
public Ackerman(int n,int m) throws IOException
{
this.n=n;
this.m=m;
result=ackerman(n,m);
display();
}
public int ackerman(int n,int m)
{
if(n==1&&m==0)
{
return 2;
}
if(n==0&&m>=0)
{
return 1;
}
if(n>=2&&m==0)
{
return n+2;
}
return ackerman(ackerman(n-1,m),m-1);
}
public void display() throws IOException
{
BufferedWriter fout=new BufferedWriter(new FileWriter("out.txt"));
fout.write("result="+result);
fout.flush();
}
}
三 . 运行结果
Ackerman myAckerman=new Ackerman(10, 2);

enter description here
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如果单表数据量大,只能考虑分库分表吗?
· 一文彻底搞懂 MCP:AI 大模型的标准化工具箱
· 电商平台中订单未支付过期如何实现自动关单?
· 用 .NET NativeAOT 构建完全 distroless 的静态链接应用
· 为什么构造函数需要尽可能的简单
· 短信接口被刷爆:我用Nginx临时止血
· Google发布A2A开源协议:“MCP+A2A”成未来标配?
· C# 多项目打包时如何将项目引用转为包依赖
· 一款让 Everything 更加如虎添翼的 .NET 开源辅助工具!
· 如果单表数据量大,只能考虑分库分表吗?