Java Math.toIntExact() methodThe 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 1Test it NowOutput: 230 Example 2Test it NowOutput: -829 Example 3Test it NowOutput: Exception in thread "main" java.lang.ArithmeticException: integer overflow at java.lang.Math.toIntExact(Math.java:1011) at toIntExactExample3.main(toIntExactExample3.java:6) Example 4Test it NowOutput: 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
|