package integer.overflow; /** * * @author justi */ public class IntegerOverflow_Mitigated { /** * @param args the command line arguments */ public static void main(String[] args) { //int a is equal to the largest int available int a = Integer.MAX_VALUE; int b = 1; //calculation will result in integer overflow int c = a + b; System.out.println("Before: " + a + " + " + b + " = " + c); System.out.println("After: " + Math.addExact( a, b )); } }