Java Math.toIntExact() methodLast Updated : 17 Mar 2025 The java.lang.Math.toIntExact() returns the value of long argument. It will throw an exception if the result overflows either int or long. SyntaxParameterReturn
Example 1Output: 230 Example 2Output: -829 Example 3Output: Exception in thread "main" java.lang.ArithmeticException: integer overflow at java.lang.Math.toIntExact(Math.java:1011) at toIntExactExample3.main(toIntExactExample3.java:6) Example 4Output: Exception in thread "main" java.lang.ArithmeticException: integer overflow at java.lang.Math.toIntExact(Math.java:1011) at toIntExactExample4.main(toIntExactExample4.java:6) Next TopicJava Math |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India