Skip to content

Commit 9c665f2

Browse files
authored
Add files via upload
1 parent d12ddb9 commit 9c665f2

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package ch_10;
2+
3+
import java.math.BigDecimal;
4+
import java.math.BigInteger;
5+
6+
/**
7+
* 10.21 (Divisible by 5 or 6) Find the first ten numbers greater than Long.MAX_VALUE
8+
* that are divisible by 5 or 6.
9+
*/
10+
public class Exercise10_21 {
11+
public static void main(String[] args) {
12+
BigInteger testNumber = BigInteger.valueOf(Long.MAX_VALUE);
13+
BigInteger FIVE = BigInteger.valueOf(5L);
14+
BigInteger SIX = BigInteger.valueOf(6L);
15+
16+
int count = 0;
17+
while (count < 10) {
18+
testNumber = testNumber.add(BigInteger.ONE);
19+
20+
BigInteger remainder = testNumber.remainder(FIVE);
21+
if (remainder.intValue() == 0) {
22+
System.out.print("\n" + testNumber.toString());
23+
System.out.print(" divided by 5 = ");
24+
BigInteger res = testNumber.divide(FIVE);
25+
System.out.print(res.toString());
26+
count++;
27+
}
28+
29+
BigInteger remainder6 = testNumber.remainder(SIX);
30+
if (remainder6.intValue() == 0) {
31+
System.out.print("\n" + testNumber.toString());
32+
System.out.print(" divided by 6 = ");
33+
BigInteger res = testNumber.divide(SIX);
34+
System.out.print(res.toString());
35+
count++;
36+
}
37+
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)