Skip to content

Commit 04a423d

Browse files
authored
Add files via upload
1 parent 50180f0 commit 04a423d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package ch_10;
2+
3+
import java.math.BigDecimal;
4+
5+
/**
6+
* 10.16 (Divisible by 2 or 3) Find the first ten numbers with 50 decimal digits that are
7+
* divisible by 2 or 3.
8+
*/
9+
public class Exercise10_16 {
10+
public static void main(String[] args) {
11+
BigDecimal bigDecimal = new BigDecimal("10000000000000000000000000000000000000000000000000");
12+
int count = 0;
13+
while (count < 10) {
14+
BigDecimal remainder2 = bigDecimal.remainder(BigDecimal.valueOf(2L));
15+
if (remainder2.intValue() == 0) {
16+
System.out.print("\n" + bigDecimal.toPlainString());
17+
System.out.print(" divided by 2 = ");
18+
BigDecimal res = bigDecimal.divide(BigDecimal.valueOf(2L));
19+
System.out.print(res.toPlainString());
20+
count++;
21+
}
22+
23+
BigDecimal remainder3 = bigDecimal.remainder(BigDecimal.valueOf(3L));
24+
if (remainder3.intValue() == 0) {
25+
System.out.print("\n" + bigDecimal.toPlainString());
26+
System.out.print(" divided by 3 = ");
27+
BigDecimal res = bigDecimal.divide(BigDecimal.valueOf(3L));
28+
System.out.print(res.toPlainString());
29+
count++;
30+
}
31+
32+
bigDecimal = bigDecimal.add(BigDecimal.ONE);
33+
}
34+
}
35+
36+
}

0 commit comments

Comments
 (0)