-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem5.java
More file actions
38 lines (33 loc) · 854 Bytes
/
Problem5.java
File metadata and controls
38 lines (33 loc) · 854 Bytes
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
//2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
//
//What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
public class Problem5 {
public static void main(String[] args) {
int smallest = 0;
boolean divisible = false;
int val = 2520;
do {
if (divisible(val)) {
smallest = val;
divisible = true;
val++;
}
else {
val++;
}
} while (divisible == false);
System.out.println("Smallest value is: " + smallest);
}
private static boolean divisible(int value) {
boolean div = true;
for(int i=3; i<21; i++){
if(value%i==0) {
continue;
}
else {
div = false;
}
}
return div;
}
}