Skip to content

Instantly share code, notes, and snippets.

@shuhei
Created February 23, 2020 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuhei/2e0eb6d8f70c4b7c8dcb9c884d22d631 to your computer and use it in GitHub Desktop.
Save shuhei/2e0eb6d8f70c4b7c8dcb9c884d22d631 to your computer and use it in GitHub Desktop.
Java int overflow
public class Main {
public static void main(String[] args) {
System.out.println(Integer.MIN_VALUE); // -2147483648
System.out.println(Integer.MAX_VALUE); // 2147483647
System.out.println(Integer.MAX_VALUE + 1); // -2147483648
System.out.println(-Integer.MIN_VALUE); // -2147483648
System.out.println(-(Integer.MIN_VALUE + 1)); // 2147483647
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment