How to print a value here instead of return? [Java] [Solved] | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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