forked from HarryDulaney/intro-to-java-programming
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExercise10_21.java
40 lines (34 loc) · 1.29 KB
/
Exercise10_21.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
package ch_10;
import java.math.BigDecimal;
import java.math.BigInteger;
/**
* 10.21 (Divisible by 5 or 6) Find the first ten numbers greater than Long.MAX_VALUE
* that are divisible by 5 or 6.
*/
public class Exercise10_21 {
public static void main(String[] args) {
BigInteger testNumber = BigInteger.valueOf(Long.MAX_VALUE);
BigInteger FIVE = BigInteger.valueOf(5L);
BigInteger SIX = BigInteger.valueOf(6L);
int count = 0;
while (count < 10) {
testNumber = testNumber.add(BigInteger.ONE);
BigInteger remainder = testNumber.remainder(FIVE);
if (remainder.intValue() == 0) {
System.out.print("\n" + testNumber.toString());
System.out.print(" divided by 5 = ");
BigInteger res = testNumber.divide(FIVE);
System.out.print(res.toString());
count++;
}
BigInteger remainder6 = testNumber.remainder(SIX);
if (remainder6.intValue() == 0) {
System.out.print("\n" + testNumber.toString());
System.out.print(" divided by 6 = ");
BigInteger res = testNumber.divide(SIX);
System.out.print(res.toString());
count++;
}
}
}
}