Tuesday, January 31, 2012

There's Madness in the Methods

I just learned how to write methods. They seem to be handy for doing repetitive functions within a program. A good example that came up was the pre defined method to calculate the square root of something. Although there is a long mathematical way to calculate the square root, most people don't want to do this every time they want the square root of a number. Luckily someone came up with a method to do all the long mathematics for everyone, so now all I need to do is call the square root method which I believe is Math.sqrt(). I can see where this will be handy in situations where I have been copy and pasting code over and over within the same program. Now I can just refer to one method to do calculations for me. I don't really understand call stacks yet, but then again they are kind of like the method of a method... weird! Maybe I'll research stacks and post back on what I've found later. Things to remember: - Cannot have a method within a method (at least in Java) - different types of methods for example: int, double, string - you CAN have a method that doesn't return a value, but rather does something instead, like print something that is inputted. Things that are still confusing: - I'm slightly confused about the order that things occur while using methods, but I'm sure with a little practice it will make more sense - Quantum Mechanics =p

No comments:

Post a Comment