Meta comments
Is your intention to create a separate Java program for each of the hundreds of Project Euler problems? If you plan on completing more than a handful of them, I would recommend finding a way to consolidate your solutions to all problems into a single program. You will find a significant amount of overlap between certain questions, so being able to create "helper" routines will benefit you greatly. Consider adding in some testing, validation, and timing framework to make sure your results are correct and being solved within a reasonable amount of time (i.e., PE's suggested 1-minute duration).
Algorithmic Comments
As this is a code review, and not an algorithm review, and because I don't want to spoil yours or anyone else's Project Euler experience, I'll keep this brief. Your algorithm is good; you've already used the closed-form equation for these triangle numbers and done some math. You can actually take the math a step further, but then the programming is trivialized and entirely problem #1-specific.
Code Comments
Creating the general sumMultiple()
routine is good, as it is general enough to probably prove useful later on.
I would highly recommend factoring this line into its own problem001()
subroutine:
sumMupltiple(3, 1000) + sumMupltiple(5, 1000) - sumMupltiple(15, 1000));
Then in your main()
function, you need only do:
System.out.println(problem001());
And the self-documenting nature of that naming scheme makes it pretty clear that you are printing the result of problem 001. It might seem a little silly in this case, but not all problems will be one-liners, and consistency is probably better than brevity in this case.
If you do decide to take some of my "meta comments" advice later, it will be even easier to organize your program.