Jump to content

Basic Java question in regards to Methods

e4effort
Go to solution Solved by Gachr,

Generally yes, it helps a lot when debugging, and makes your code more neat.

Hello LTT community.

 

I'm learning Java for a few weeks now and I'm really enjoying it. Problem solving that goes with it really makes you think.

I have a question around methods.

 

Im writing a simple text game.. No user interaction is really required except for the odd part here and there. Nothing fancy.

My question is, should I be using methods? Should each part of my program be split up using the methods? 

For example, should my Welcome section be put as a method? Then the actual game part of a method? The scorings part of a separate method?

 

Many thanks for any help.

 

Link to comment
Share on other sites

Link to post
Share on other sites

Generally yes, it helps a lot when debugging, and makes your code more neat.

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, Gachr said:

Generally yes, it helps a lot when debugging, and makes your code more neat.

Okay. Many thanks. 

Link to comment
Share on other sites

Link to post
Share on other sites

11 hours ago, Gachr said:

Generally yes, it helps a lot when debugging, and makes your code more neat.

not only does it help with debugging and making code neater and more organized, it also helps with allowing easy code reuse. if you have a very specific method, you can call on it any number of times necessary. or if you have some common methods you can use the same core logic across the program very easily

Link to comment
Share on other sites

Link to post
Share on other sites

Breaking your code into methods is sort of like taking a large task and breaking it up into bits, though in this case all it will do is make debugging easier, look neater, and allow you to reuse the code more easily.

This will become especially clear once you start making your own classes, which you may even want to do now just to get the hang of it.

CPU - Ryzen 7 3700X | RAM - 64 GB DDR4 3200MHz | GPU - Nvidia GTX 1660 ti | MOBO -  MSI B550 Gaming Plus

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×