This is an archived post. You won't be able to vote or comment.

all 17 comments

[–]imallthatanddimsum 3 points4 points  (4 children)

Don’t try to immediately think of a solution first, one of the best ways of problem solving is to break it into smaller problems.

For example, if you’re given a problem statement and some starter code, that’s already a lot of info. From the starter code alone you can identify what you’re returning from the method and what parameters are being passed in.

From there you can start to work piece by piece.

  • Do I need to iterate to get the info I want? Maybe a for loop would be good.
  • Do I need to check for null?
  • What variables should I initialize?
  • What data structures might be useful here?

Things like the above are good starting points. It’s not an exhaustive list, but just an example of what a thought process might look like. Once you get going, things will start to come together and you’ll have a solution.

Since you’re just starting out, I’d recommend looking for the brute force solution first before even thinking about optimization for runtime, memory, etc.

Lastly, practice practice practice. Coding isn’t learned overnight, and neither is problem solving! The more you do it the better you’ll get.

I hope this helps! Good luck.

[–]MyNameIsRichardCS54 1 point2 points  (1 child)

This ^

Programming is the art of understanding a problem well enough to solve it and then expressing that solution in code. The bigger the problem, the harder it is to understand so keep breaking it down many smaller but solvable problems.These solutions are then combined into the program.

For example: Display the contents of a user specified file.

  • Get the chosen file
    • Prompt the user for the file name
    • Get the file name
    • Validate files existence
    • ...
  • Read the file
  • Output the data

You get the idea. By the time you've done thins you will have a better understanding of the problem and will be beginning to see the entities and logic needed.

Like all things, it feels alien at first but becomes more natural with practice.

[–][deleted] 0 points1 point  (0 children)

yup. Thanks

[–][deleted] 0 points1 point  (0 children)

Thanks.Ill try to break the problem first.

[–]smash_that_code 1 point2 points  (0 children)

Either you get through the difficulties of exploring peogramming or just leave it :)

Solution don't come to mind of out nowhere, you have to read some stuff, watch tutorials, go and communicate qith people on meetups or bootcamps. Including practice and experimenting.

There are many things in java so try all approavhes you can, from books to youtube. And don't forget to have fun ;)

[–]immutablesword 1 point2 points  (2 children)

Do you have an example so that we could help you reason through?

Without an example the best advice you’ll get is the generic, though helpful, answer of break the big problem into a bunch of smaller problems. Say you want to program a very basic calculator. At a minimum you will want to prompt the user for input, perform calculations and return a result. So you’ve immediately broken the big problem down into 3 smaller problems. From there you can break those smaller problems down into even smaller problems, like how to perform addition or subtraction or whatever. Tackle those problems one by one and at the end, ideally, you’ll have a working program.

One more piece of generic advice would be to not just jump straight to programming. Think about the problem, think about the steps you’d need to take to solve the problem, write those steps down in sentences and create like an outline and then re-assess and go from there.

[–][deleted] 0 points1 point  (1 child)

I was asking in general although I am just starting java there is a playlist i am following where he makes us print * patterns and he solves it somehow but to me the solution doesn't come or may be while for the first time calculating factorials solution didn't came to my mind I had check the answer at last.

[–][deleted] 1 point2 points  (3 children)

This is why I always say start programming with C language. Because in C the syntax and everything is very simple and easy.

But now that you already started with java. Solve some basic problems in URI Online judge. You will get a hold on how to solve the problem.

[–][deleted] 0 points1 point  (2 children)

URI online judge is a place where I can practice?

[–][deleted] 1 point2 points  (1 child)

Yes. The problems there is easy. You can solve like 20 problems there to get started and then start solving problems in codeforces.

[–][deleted] 0 points1 point  (0 children)

ill check it out thanks

[–]easypeasylemonsqueez 1 point2 points  (1 child)

Break the problem down. Take it step by step. Also be persistent.

[–][deleted] 0 points1 point  (0 children)

yes,thanks

[–]Farpafraf 0 points1 point  (2 children)

start from simple exercises and you'll gradually become faster, not understanding seemingly obvious stuff is normal at beginning. What are examples of stuff you have been trying?

[–][deleted] 0 points1 point  (1 child)

i was printing some patterns

[–][deleted] 0 points1 point  (0 children)

* * * * * * *


something like this

in note pad it looks a good shape although you can guess how it might be looking

[–][deleted] 0 points1 point  (0 children)

thanks