+ 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;
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;
}
+ 4
Rabeeh
Your method should be void if you don't want to return anything.
Can you show your code?
+ 1
Hey, sorry for late reply. Here's the code.
https://code.sololearn.com/cA9A215A21a1/?ref=app
I Am AJ !