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