Java | Create an explicit addition function only using recursion and conditionals

前端 未结 2 1651
南笙
南笙 2021-01-23 18:30

Preface

By finding some free time in my schedule, I quested myself into improving my recursion skills (unfortunately). As practice, I want to recreate a

2条回答
  •  不知归路
    2021-01-23 19:04

    public static int add (int a, int b) {
        if (b == 0) return a;
        if (b > a) return add (b, a);
        add (++a, --b);
    }
    

    Just with ++/--.

提交回复
热议问题