首页 > 其他 > 详细

Ackerman

时间:2018-11-11 14:51:55      阅读:205      评论:0      收藏:0      [点我收藏+]

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

 

Ackerman

原文:https://www.cnblogs.com/Howbin/p/9942018.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!