This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Return types and methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Return types and methods" Watch "Return types and methods" New topic

Return types and methods

Alix Ollivier
Ranch Hand

Joined: Jun 04, 2012
Posts: 71

Each time I want to move my character in the game I am building, I do code like this. and I write goLeft like this:

Is this correct, to call a return and have it call to itself? Or is there a way I can simply call goLeft without the accompanying coordinateX=? Coordinate X and Y are outside of the method.

"The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!', but 'That's funny...' "
- Isaac Asimov
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10175

I wouldn't call it incorrect but I think a more elegant approach would be

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

I would just do this:

It is sorta covered in the JavaRanch Style Guide.
subject: Return types and methods
Similar Threads
regarding long and float
what this signature means?
convert scientific notation number format to normal number format
My code should draw Julia set but instead it does not draw anything
the code does not call paint method