why must use return? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why must use return?

I dont understand why we must use return keyword.... I try use or not..the result is same can output a result

21st Nov 2016, 6:06 AM
M Yusuf
M Yusuf - avatar
3 Answers
0
In functions that returns some values you must use this keyword. For example this function: public int func (int a, int b ){int c = a+b; return c} will return the value of int type and you can use this value in your code.
21st Nov 2016, 6:19 AM
Andrei
Andrei - avatar
0
while using datatype in method like public int(datatype) add() we should use return keyword otherwise use void as a data type to avoid return keyword
21st Nov 2016, 1:33 PM
Gajenthiran.V
Gajenthiran.V - avatar
0
When you use return, the function returns(sends) a value to the other method where it was called. It does not print whereas if you use system. out.print it will print and your main method will receive no value
25th Nov 2016, 1:09 PM
Kshitij Jain
Kshitij Jain - avatar