Understanding the return concept for this exercise

I am struggling to understand why a return is needed. My code is functional both with and without this “return” method? Please elaborate?

Could you provide the link to the exercise in question ??

The return method… I have had trouble with that keyword when i was a begginer… but this is all it is:

public int add(int x, int y){
  return x+y;

SO here its returning x+y… THAT MEANS… when you call it, then you can set a variable to it… basically…

int result = add(3,4);

So NOW since the add function returns an int… right there it becomes

int result = 3+4;

which autmoatically gets compiled to…

int result = 7;


1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.