Posted By

itaiferber on 09/18/10


Tagged

java project-euler ap-comp-sci


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

deggial
ovunccetin


Project Euler - Problem 1


 / Published in: Java
 

The solution to Project Euler Problem 1, written in Java as an example for my AP Computer Science class teaching internship.

  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  

You need to login to post a comment.