小编Jos*_*man的帖子

很奇怪为什么这个递归代码不起作用,并且在另一个方法中表现出非常不合理的行为

这里是新程序员,对于我认为递归的一些代码存在一些问题.

public static int sum (int a) {
    int input = goodInput(); //get input from below method without having to put its code in this one
    if (input==-1)//so user has the ability to exit at any time
        return a; //when user has finally entered -1, the final sum is sent out
    else; //for scenarios before last input 
    int b = a + input; //adding the newest input to the sum 
    int c = sum(b); //throw the total into the method …
Run Code Online (Sandbox Code Playgroud)

java recursion input while-loop

2
推荐指数
1
解决办法
74
查看次数

标签 统计

input ×1

java ×1

recursion ×1

while-loop ×1