I do not understand why the system.out.println(sqr(5)); part is so early in the code? why isn't it at the end instead of being in the main method?
I am asking be cause the a*a part comes after the print statement..so how is it printing before it gets the answer??? maybe I am looking at this the wrong way
square of number
Under discussion
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Anonymous #11474101
19 February, 14:24
Thank
0
Tyler Begrow
14 January 2020, 03:34useful
This is because the main method is the entry point for your program. It takes priority over everything else. They could have put the sqr() method before main and the answer would be the same. The important part is that the sqr() method is defined so the main method can call it and then complete the rest of the tasks that are in main. Think of it like a detour.
+2
Jo88
14 January 2020, 04:18
thanks!
+1
Tyler Begrow
14 January 2020, 21:15
You're welcome!
0