Quantcast
Viewing latest article 6
Browse Latest Browse All 10

Project Euler #1

Project Euler is a series of increasingly challenging math-based programming challenges. The easiest of the problems have been solved by hundreds of thousands of people, the toughest have been solved by less than 100 people worldwide. I may or may not continue to attempt these problems in my spare-time, below is my solution for #1.

PROBLEM: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.

//BTG 2.10.14

public class euler{
    public static void main(String[] args){
    
    int answer = 0;
      
    for (int i = 1; i < 1000; i++){
        if(i % 3 == 0)
            answer += i;
        
        else if(i % 5 == 0)
            answer += i;
      }
    
    System.out.println(answer);
    
    }   
}

Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing latest article 6
Browse Latest Browse All 10

Trending Articles