File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
OOP in Java/Chapter 10 - Object-Oriented Thinking/Code_Example Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments