+ 2

Hi, I started learning Java and I have a question, I can not understand the use of the return command, thank you .

Java

30th Nov 2020, 11:16 AM
Amir Mardani
3 ответов
+ 3
It is used for giving value when we call function in code
30th Nov 2020, 11:19 AM
Sâñtôsh
Sâñtôsh - avatar
+ 1
in short and simple for example if the method was void you don't need that and you may define output with system.out.println() but if it was something like <<public int integer(){ }>> you need to use it otherwise how you want to define that what do you want from that method as output and the return type most be the same as variable type.
30th Nov 2020, 12:49 PM
hamid
hamid - avatar
0
it just leave some value that u can use after u run that method example: int func () { return 2; } int num = func(); //call func,func run then give u back number 2 now num will equal to 2
30th Nov 2020, 11:27 AM
durian
durian - avatar