-
Notifications
You must be signed in to change notification settings - Fork 0
/
Euler1.java
executable file
·67 lines (60 loc) · 1.49 KB
/
Euler1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
*
* @author Bartholomew Brandner
* @version 1.1
* <p>
* Programmed for solving Project Euler #1
* <ul>
* <li>Version 1.0 Initially programmed on 11/24/2009</li>
* <li>Version 1.1 Javadoc additions added on 7/5/2013</li>
* </ul>
* <br>
* I realize that for such a simple program, the amount of comments are
* probably unnecessary. However, I also believe strongly in good, thorough
* documentation. The heavy commenting is merely an extension of that
* philosophy.
* <br><br>
* Always code as if the guy who ends up maintaining your code will be a
* violent psychopath who knows where you live. --Martin Golding
*</p>
*/
public class Euler1
{
private long answer; //stores answer
/**
* The constructor for this class only initializes the answer to 0.
*/
public void Euler1()
{
answer = 0;
}
/**
* The meat of the program, all calculations are performed in this method.
*/
public void oneToOneThousand()
{
System.out.println("Multiples:\tSum:");
for( int i = 0; i < 1000; i++ )
{
if( ((i % 3) == 0) || ((i % 5) == 0) ) //tests to see if i is a multiple of 3 or 5
{
answer += i;
System.out.println(i + "\t\t" + answer);
}
}
}
/**
* Merely returns the answer variable
* @return returns sum of multiples
*/
public long getAnswer()
{
return answer;
}
public static void main(String[] args)
{
Euler1 theAnswer = new Euler1();
theAnswer.oneToOneThousand();
System.out.println("Final sum is: " + theAnswer.getAnswer());
}
}