java - 关于递归方法的问题
黄舟
黄舟 2017-04-18 10:54:36
0
1
398

为什么最后会报错?

    public static int count(int n){
        int result;
        result = n/4+count(n-4);
        if (n<0)
            result = 0;
        return result;
    }
    
    public static void main(String[] args){
        System.out.println(count(5));
    }

Exception in thread "main" java.lang.StackOverflowError

at huam.count(huam.java:4)
at huam.count(huam.java:4)
at huam.count(huam.java:4)
at huam.count(huam.java:4)
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
Ty80
public static int count(int n){
        if (n<0)
            return 0;
        return n/4+count(n-4);
    }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!