import java.io.PrintStream; import java.util.Scanner; import type.lib.ToolBox; import javax.swing.JOptionPane; public class Overflow { public static void main(String[] args) { Scanner input = new Scanner(System.in); PrintStream output = System.out; //output.print("Provide a positive integer: "); String firstString = JOptionPane.showInputDialog(null, "Provide a positive integer"); int first = Integer.parseInt(firstString); ToolBox.crash(first < 0, "Provide a positive integer"); //output.print("Provide a positive integer: "); String secondString = JOptionPane.showInputDialog(null, "Provide a positive integer"); int second = Integer.parseInt(secondString); ToolBox.crash(second < 0, "Provide a positive integer"); boolean overflow = (long) first + (long) second > Integer.MAX_VALUE; JOptionPane.showMessageDialog(null, overflow, "Is there overflow?", JOptionPane.INFORMATION_MESSAGE); //output.printf("Is there overflow? %b%n", overflow); } }