+ 1

How to print a value here instead of return? [Java] [Solved]

when I give a value to method, instead of return, I want to print the result but I can't do that in IDE (intellij) it shows "missing return statement" when I add System.out.println(ans); instead of return ans;

26th Feb 2021, 4:14 PM
Ray
Ray - avatar
3 Respostas
+ 1
Rabeeh If your method has return type (except void) then you have to return something otherwise you will get that error. So if you want to print result then just do like this System.out.println(conv(1)); Or you can do like this also static int conv(int hours){ int ans = hours * 3600; System.out.println(ans); return ans; }
28th Feb 2021, 9:51 AM
A͢J
A͢J - avatar
+ 4
Rabeeh Your method should be void if you don't want to return anything. Can you show your code?
26th Feb 2021, 4:33 PM
A͢J
A͢J - avatar
+ 1
Hey, sorry for late reply. Here's the code. https://code.sololearn.com/cA9A215A21a1/?ref=app I Am AJ !
28th Feb 2021, 9:33 AM
Ray
Ray - avatar