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–2017, Robert Sedgewick and Kevin Wayne.
Last updated: Fri Oct 20 14:12:12 EDT 2017.