Project Euler - Problem 1


/ Published in: Java
Save to your folder(s)

The solution to Project Euler [Problem 1](http://projecteuler.net/index.php?section=problems&id=1), written in Java as an example for my AP Computer Science class teaching internship.


Copy this code and paste it in your HTML
  1. public class Euler {
  2. public static void main (String[] args) {
  3. int sum = 0;
  4. for (int counter = 1; counter < 1000; counter++) {
  5. if ((counter % 3) == 0 || (counter % 5) == 0) {
  6. sum += counter;
  7. }
  8. }
  9.  
  10. System.out.print("The sum of all multiples of 3 and 5 below 1000 is " + sum + ".");
  11. }
  12. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.