File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programming Diversions and the fly likes Euler problem #1 - Spoiler Alert! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Other » Programming Diversions
Reply Bookmark "Euler problem #1 - Spoiler Alert!" Watch "Euler problem #1 - Spoiler Alert!" New topic
Author

Euler problem #1 - Spoiler Alert!

J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 394
    
    3

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?


"There is no reason for any individual to have a computer in his home" ~ Ken Olson, Co-founder of DEC, 1977
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 3860
    
    1

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
Ranch Hand

Joined: Dec 16, 2010
Posts: 394
    
    3

Thanks, excellent advice. This is why I like to ask for a different perspective on things. New code:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Euler problem #1 - Spoiler Alert!
 
Similar Threads
Project Euler Problem 25
Project Euler problems with Scala
Project Euler #17
how many project Euler problems have you solved?
multiples project (three five) project euler