+ 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

22nd May 2019, 2:58 PM
Ayush Pandey
Ayush Pandey - avatar
6 Answers
+ 3
Yes return and print are totally different.
23rd May 2019, 12:14 PM
Abhinav
+ 2
Because you have not print anything.
22nd May 2019, 3:05 PM
Abhinav
+ 2
Abhinav Bhardwaj but it should return the argument of the function
22nd May 2019, 3:07 PM
Ayush Pandey
Ayush Pandey - avatar
+ 2
Abhinav Bhardwaj and Airree are return and print statements not same ? have I misunderstood some concepts?
22nd May 2019, 3:09 PM
Ayush Pandey
Ayush Pandey - avatar
+ 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
22nd May 2019, 3:11 PM
Airree
Airree - avatar
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); }
22nd May 2019, 3:07 PM
Airree
Airree - avatar