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
You must be signed in to leave a comment
14 January 2020, 03:34
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.
14 January 2020, 04:18
14 January 2020, 21:15