CSC231 MultBy3.java Program
--D. Thiebaut 08:08, 3 October 2012 (EDT)
// MultBy3.java
// D. Thiebaut
// A simple program to illustrates what happens when an overflow occurs
// in an int variable.
//
// To compile and run:
// javac MultBy3.java
// java MultBy3
//
public class MultBy3 {
public static void main( String[] args ) {
int a = 2;
for ( int i=0; i<70; i++ ) {
System.out.println( a );
//System.out.println( String.format( "%20d %16s %64s", a , Long.toHexString(a), Long.toBinaryString( a ) ) );
//System.out.println( String.format( "%12d %8s %32s", a , Integer.toHexString(a), Integer.toBinaryString( a ) ) );
a *= 3;
}
}
}
Contents
Outputs
With int as the type
2
6
18
54
162
486
1458
4374
13122
39366
118098
354294
1062882
3188646
9565938
28697814
86093442
258280326
774840978
-1970444362
-1616365790
-554130074
-1662390222
-692203370
-2076610110
-1934863034
-1509621806
-233898122
-701694366
-2105083098
-2020281998
-1765878698
-1002668798
1286960902
-434084590
-1302253770
388205986
1164617958
-801113422
1891627030
1379913794
-155225914
-465677742
-1397033226
103867618
311602854
934808562
-1490541610
-176657534
-529972602
-1589917806
-474786122
-1424358366
21892198
65676594
197029782
591089346
1773268038
1024836818
-1220456842
633596770
1900790310
1407403634
-72756394
-218269182
-654807546
-1964422638
-1598300618
-499934558
-1499803674
With int as type, showing hex and binary
2 2 10
6 6 110
18 12 10010
54 36 110110
162 a2 10100010
486 1e6 111100110
1458 5b2 10110110010
4374 1116 1000100010110
13122 3342 11001101000010
39366 99c6 1001100111000110
118098 1cd52 11100110101010010
354294 567f6 1010110011111110110
1062882 1037e2 100000011011111100010
3188646 30a7a6 1100001010011110100110
9565938 91f6f2 100100011111011011110010
28697814 1b5e4d6 1101101011110010011010110
86093442 521ae82 101001000011010111010000010
258280326 f650b86 1111011001010000101110000110
774840978 2e2f2292 101110001011110010001010010010
-1970444362 8a8d67b6 10001010100011010110011110110110
-1616365790 9fa83722 10011111101010000011011100100010
-554130074 def8a566 11011110111110001010010101100110
-1662390222 9ce9f032 10011100111010011111000000110010
-692203370 d6bdd096 11010110101111011101000010010110
-2076610110 843971c2 10000100001110010111000111000010
-1934863034 8cac5546 10001100101011000101010101000110
-1509621806 a604ffd2 10100110000001001111111111010010
-233898122 f20eff76 11110010000011101111111101110110
-701694366 d62cfe62 11010110001011001111111001100010
-2105083098 8286fb26 10000010100001101111101100100110
-2020281998 8794f172 10000111100101001111000101110010
-1765878698 96bed456 10010110101111101101010001010110
-1002668798 c43c7d02 11000100001111000111110100000010
1286960902 4cb57706 1001100101101010111011100000110
-434084590 e6206512 11100110001000000110010100010010
-1302253770 b2612f36 10110010011000010010111100110110
388205986 17238da2 10111001000111000110110100010
1164617958 456aa8e6 1000101011010101010100011100110
-801113422 d03ffab2 11010000001111111111101010110010
1891627030 70bff016 1110000101111111111000000010110
1379913794 523fd042 1010010001111111101000001000010
-155225914 f6bf70c6 11110110101111110111000011000110
-465677742 e43e5252 11100100001111100101001001010010
-1397033226 acbaf6f6 10101100101110101111011011110110
103867618 630e4e2 110001100001110010011100010
311602854 1292aea6 10010100100101010111010100110
934808562 37b80bf2 110111101110000000101111110010
-1490541610 a72823d6 10100111001010000010001111010110
-176657534 f5786b82 11110101011110000110101110000010
-529972602 e0694286 11100000011010010100001010000110
-1589917806 a13bc792 10100001001110111100011110010010
-474786122 e3b356b6 11100011101100110101011010110110
-1424358366 ab1a0422 10101011000110100000010000100010
21892198 14e0c66 1010011100000110001100110
65676594 3ea2532 11111010100010010100110010
197029782 bbe6f96 1011101111100110111110010110
591089346 233b4ec2 100011001110110100111011000010
1773268038 69b1ec46 1101001101100011110110001000110
1024836818 3d15c4d2 111101000101011100010011010010
-1220456842 b7414e76 10110111010000010100111001110110
633596770 25c3eb62 100101110000111110101101100010
1900790310 714bc226 1110001010010111100001000100110
1407403634 53e34672 1010011111000110100011001110010
-72756394 fba9d356 11111011101010011101001101010110
-218269182 f2fd7a02 11110010111111010111101000000010
-654807546 d8f86e06 11011000111110000110111000000110
-1964422638 8ae94a12 10001010111010010100101000010010
-1598300618 a0bbde36 10100000101110111101111000110110
-499934558 e2339aa2 11100010001100111001101010100010
-1499803674 a69acfe6 10100110100110101100111111100110
Output with long as the type
2 2 10
6 6 110
18 12 10010
54 36 110110
162 a2 10100010
486 1e6 111100110
1458 5b2 10110110010
4374 1116 1000100010110
13122 3342 11001101000010
39366 99c6 1001100111000110
118098 1cd52 11100110101010010
354294 567f6 1010110011111110110
1062882 1037e2 100000011011111100010
3188646 30a7a6 1100001010011110100110
9565938 91f6f2 100100011111011011110010
28697814 1b5e4d6 1101101011110010011010110
86093442 521ae82 101001000011010111010000010
258280326 f650b86 1111011001010000101110000110
774840978 2e2f2292 101110001011110010001010010010
2324522934 8a8d67b6 10001010100011010110011110110110
6973568802 19fa83722 110011111101010000011011100100010
20920706406 4def8a566 10011011110111110001010010101100110
62762119218 e9ce9f032 111010011100111010011111000000110010
188286357654 2bd6bdd096 10101111010110101111011101000010010110
564859072962 83843971c2 1000001110000100001110010111000111000010
1694577218886 18a8cac5546 11000101010001100101011000101010101000110
5083731656658 49fa604ffd2 1001001111110100110000001001111111111010010
15251194969974 ddef20eff76 11011101111011110010000011101111111101110110
45753584909922 299cd62cfe62 1010011001110011010110001011001111111001100010
137260754729766 7cd68286fb26 11111001101011010000010100001101111101100100110
411782264189298 176838794f172 1011101101000001110000111100101001111000101110010
1235346792567894 4638a96bed456 100011000111000101010010110101111101101010001010110
3706040377703682 d2a9fc43c7d02 1101001010101001111111000100001111000111110100000010
11118121133111046 277fdf4cb57706 100111011111111101111101001100101101010111011100000110
33354363399333138 767f9de6206512 1110110011111111001110111100110001000000110010100010010
100063090197999414 1637ed9b2612f36 101100011011111101101100110110010011000010010111100110110
300189270593998242 42a7c8d17238da2 10000101010011111001000110100010111001000111000110110100010
900567811781994726 c7f75a7456aa8e6 110001111111011101011010011101000101011010101010100011100110
2701703435345984178 257e60f5d03ffab2 10010101111110011000001111010111010000001111111111101010110010
8105110306037952534 707b22e170bff016 111000001111011001000101110000101110000101111111111000000010110
5868586844404305986 517168a4523fd042 101000101110001011010001010010001010010001111111101000001000010
-840983540496633658 f45439ecf6bf70c6 1111010001010100001110011110110011110110101111110111000011000110
-2522950621489900974 dcfcadc6e43e5252 1101110011111100101011011100011011100100001111100101001001010010
-7568851864469702922 96f60954acbaf6f6 1001011011110110000010010101010010101100101110101111011011110110
-4259811519699557150 c4e21bfe0630e4e2 1100010011100010000110111111111000000110001100001110010011100010
5667309514610880166 4ea653fa1292aea6 100111010100110010100111111101000010010100100101010111010100110
-1444815529876911118 ebf2fbee37b80bf2 1110101111110010111110111110111000110111101110000000101111110010
-4334446589630733354 c3d8f3caa72823d6 1100001111011000111100111100101010100111001010000010001111010110
5443404304817351554 4b8adb5ff5786b82 100101110001010110110110101111111110101011110000110101110000010
-2116531159257496954 e2a0921fe0694286 1110001010100000100100100001111111100000011010010100001010000110
-6349593477772490862 a7e1b65fa13bc792 1010011111100001101101100101111110100001001110111100011110010010
-602036359607920970 f7a5231ee3b356b6 1111011110100101001000110001111011100011101100110101011010110110
-1806109078823762910 e6ef695cab1a0422 1110011011101111011010010101110010101011000110100000010000100010
-5418327236471288730 b4ce3c16014e0c66 1011010011001110001111000001011000000001010011100000110001100110
2191762364295685426 1e6ab44203ea2532 1111001101010101101000100001000000011111010100010010100110010
6575287092887056278 5b401cc60bbe6f96 101101101000000000111001100011000001011101111100110111110010110
1279117204951617218 11c05652233b4ec2 1000111000000010101100101001000100011001110110100111011000010
3837351614854851654 354102f669b1ec46 11010101000001000000101111011001101001101100011110110001000110
-6934689229144996654 9fc308e33d15c4d2 1001111111000011000010001110001100111101000101011100010011010010
-2357323613725438346 df491aa9b7414e76 1101111101001001000110101010100110110111010000010100111001110110
-7071970841176315038 9ddb4ffd25c3eb62 1001110111011011010011111111110100100101110000111110101101100010
-2769168449819393498 d991eff7714bc226 1101100110010001111011111111011101110001010010111100001000100110
-8307505349458180494 8cb5cfe653e34672 1000110010110101110011111110011001010011111000110100011001110010
-6475771974664989866 a6216fb2fba9d356 1010011000100001011011111011001011111011101010011101001101010110
-980571850285417982 f2644f18f2fd7a02 1111001001100100010011110001100011110010111111010111101000000010
-2941715550856253946 d72ced4ad8f86e06 1101011100101100111011010100101011011000111110000110111000000110
-8825146652568761838 8586c7e08ae94a12 1000010110000110110001111110000010001010111010010100101000010010
-8028695883996733898 909457a1a0bbde36 1001000010010100010101111010000110100000101110111101111000110110
-5639343578280650078 b1bd06e4e2339aa2 1011000110111101000001101110010011100010001100111001101010100010
1528713338867601382 153714aea69acfe6 1010100110111000101001010111010100110100110101100111111100110