+ 1

[Learning Java] What does "to return a value" mean? Im not a native speaker. Upd: I know what return means generally.

The return keyword can be used in methods to return a value. For example, we could define a method named sum that returns the sum of its two parameters.

13th Mar 2017, 6:55 PM
Alex Snaidars
Alex Snaidars - avatar
8 odpowiedzi
+ 10
Example: // method with return value: public int sum(int x, int y){ // ^ this is the type of the return value return (x+y); // ^ here is the sum returned } If you call above defined method, it will return an int, you can assign to a variable: int sum = sum(1, 2); // ^ this calls the method and // assigns the return value to your // variable You can then print the sum: System.out.print(sum); // prints the value // of the int sum, // which is 3 You can also call your method within the print statement without assigning it to a variable: System.out.print(sum(1, 2)); // prints 3
13th Mar 2017, 7:21 PM
Tashi N
Tashi N - avatar
+ 9
Sorry, I don't speak Estonian. The English definition you posted is good, try to use Google translate.
13th Mar 2017, 7:07 PM
Tashi N
Tashi N - avatar
+ 9
No. Return is used to receive (get back) a value from a method.
13th Mar 2017, 7:31 PM
Tashi N
Tashi N - avatar
+ 9
Yes, that's it.
13th Mar 2017, 7:47 PM
Tashi N
Tashi N - avatar
+ 1
Thank you.
13th Mar 2017, 7:48 PM
Alex Snaidars
Alex Snaidars - avatar
0
Some synonyms or/and explanations what happens while using 'return' function might be helpful for me. It seems that I know return means to give sth back etc
13th Mar 2017, 7:13 PM
Alex Snaidars
Alex Snaidars - avatar
0
So, return in this case means to perform a math action, to display sth.
13th Mar 2017, 7:28 PM
Alex Snaidars
Alex Snaidars - avatar
0
If I say public into sum(int x, int y) { int z = x+y; // this is the main part of the method, isn't it? return(z); // by that the value becomes accessible outside of the method, doesn't it? }
13th Mar 2017, 7:44 PM
Alex Snaidars
Alex Snaidars - avatar