We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 22bf63b commit a76dfbbCopy full SHA for a76dfbb
Project Euler/problem1/SumOfMultiples.java
@@ -0,0 +1,14 @@
1
+package problem1;
2
+
3
+public class SumOfMultiples {
4
+ int sum = 0;
5
6
+ public void addMultiples(int n) {
7
+ for (int i = 1; i < n; i++) {
8
+ if (i % 3 == 0 || i % 5 == 0) {
9
+ sum = sum + i;
10
+ }
11
12
+ System.out.println("The sum of all the multiples of 3 or 5 below " + n + " is " + sum);
13
14
+}
Project Euler/problem1/SumOfMultiplesMain.java
@@ -0,0 +1,16 @@
+import java.util.Scanner;
+public class SumOfMultiplesMain {
+ public static void main(String[] args) {
+ Scanner scanner = new Scanner(System.in);
+ int n;
+ SumOfMultiples sum = new SumOfMultiples();
+ System.out.println("Enter the number : ");
+ n = scanner.nextInt();
+ sum.addMultiples(n);
15
16
0 commit comments