It's not a secret anymore!*
The moose likes Programming Diversions and the fly likes Euler problem #1 - Spoiler Alert! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Euler problem #1 - Spoiler Alert!" Watch "Euler problem #1 - Spoiler Alert!" New topic

Euler problem #1 - Spoiler Alert!

J. Kevin Robbins

Joined: Dec 16, 2010
Posts: 828

I've finally signed up for the Euler project to improve my math and programming skills. I'm interested in feedback on my first solution. I'm not looking for the fastest solution or the least number of lines of code, but rather using sound coding practices that can be applied to any problem.

Now, how could I go about improving this code?

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
Matthew Brown

Joined: Apr 06, 2010
Posts: 4343

One thing that springs to mind is that you're effectively using two variables, i and numberToTest, for one purpose (iterating across the required range). That's more error prone because you've got to keep them in sync. I'd suggest just using numberToTest and looping from 1 to limit.
J. Kevin Robbins

Joined: Dec 16, 2010
Posts: 828

Thanks, excellent advice. This is why I like to ask for a different perspective on things. New code:
Consider Paul's rocket mass heater.
subject: Euler problem #1 - Spoiler Alert!
Similar Threads
multiples project (three five) project euler
Project Euler problems with Scala
how many project Euler problems have you solved?
Project Euler #17
Project Euler Problem 25