+ 2
why do I get no output
this is a code which I tried in java , which should take one parameter and return it via return method but it is giving no output. please explain why am I getting this problem and how to fix it Thank You :0 https://code.sololearn.com/cJYWTc1QYG1B/?ref=app
6 Respuestas
+ 3
Yes return and print are totally different.
+ 2
Because you have not print anything.
+ 2
Abhinav Bhardwaj but it should return the argument of the function
+ 2
Abhinav Bhardwaj and Airree are return and print statements not same ? have I misunderstood some concepts?
+ 1
No, they are different, the return just gives a value to the function so if you have the same code:
x = rec(1);
System.out.println(x);
//Outputs 1
0
It's because you haven't specified anywhere to print in.
The return keyword doesn't print it, it just, well, returns a value.
To print it, you have to do it like this: (in the main method)
System.out.println(rec(1));
Or:
public static int rec(int i) {
System.out.println(i);
}