returning a value from a method to another method

前端 未结 8 581
时光取名叫无心
时光取名叫无心 2021-01-19 14:42

Can somebody tell me why the value returned is 3 and not 8. Doesn\'t the return x statement from the addFive method change the value of x

8条回答
  •  攒了一身酷
    2021-01-19 15:03

    The method does return a value, but you have to set the value to a variable too when you return it, or else how would it know which variable you want to return the value to? You can have 10 variable, and if you just call the method, how will it know which variable to return the number to? That's why you have to set the returning number it to a variable like this:

    x = addFive(x);
    

提交回复
热议问题