+ 1

Why doesn't 5 get outputed?

class MyClass { static int ReturnFive() { return 5; } } public class Caller { public static void main(String[ ] args) { MyClass.ReturnFive(); } }

7th Dec 2017, 12:46 AM
Unidentified
Unidentified - avatar
4 Answers
+ 5
The return statement makes it so there is a 5 ready to be assigned or otherwise used. You, then, must tell the computer how to use it. In your program as written, you told the computer to toss it.
7th Dec 2017, 12:57 AM
John Wells
John Wells - avatar
+ 3
Try... System.out.println(MyClass.ReturnFive()); It helps to ask for output.
7th Dec 2017, 12:48 AM
John Wells
John Wells - avatar
+ 3
Nothing is done automatically. You must code what you want done and, if you fail to code it perfectly, it will run how you coded it, not how you wanted it.
7th Dec 2017, 12:53 AM
John Wells
John Wells - avatar
+ 3
Thank you very much
7th Dec 2017, 12:58 AM
Unidentified
Unidentified - avatar