Overflow.java


Below is the syntax highlighted version of Overflow.java from §6.1 Data Representations.


/******************************************************************************
 *  Compilation:  javac Overflow.java
 *  Execution:    java Overflow
 *
 *  Illustrates integer overflow.
 *
 ******************************************************************************/

public class Overflow {

    public static void main(String[] args) {

        int a = 2147483647;   // 2^31 - 1
        int b = a + 1;

        StdOut.println("a = " + a);
        StdOut.println("b = " + b);
    }

}


Copyright © 2000–2022, Robert Sedgewick and Kevin Wayne.
Last updated: Thu Aug 11 10:32:25 EDT 2022.