Ackerman

Ackerman

一 . 问题描述及分析

 

图1
图1

图2

 

二 . 代码实现

  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
enter description here

 

posted @   Howbin  阅读(448)  评论(0编辑  收藏  举报
努力加载评论中...
编辑推荐:
· 如果单表数据量大,只能考虑分库分表吗?
· 一文彻底搞懂 MCP:AI 大模型的标准化工具箱
· 电商平台中订单未支付过期如何实现自动关单?
· 用 .NET NativeAOT 构建完全 distroless 的静态链接应用
· 为什么构造函数需要尽可能的简单
阅读排行:
· 短信接口被刷爆:我用Nginx临时止血
· Google发布A2A开源协议:“MCP+A2A”成未来标配?
· C# 多项目打包时如何将项目引用转为包依赖
· 一款让 Everything 更加如虎添翼的 .NET 开源辅助工具!
· 如果单表数据量大,只能考虑分库分表吗?
点击右上角即可分享
微信分享提示