Java Math.subtractExact() methodThe java.lang.Math.subtractExact() returns the difference of the arguments. It will throw an exception if the result overflows either int or long. SyntaxParameterReturn
Example 1Test it NowOutput: 542 Example 2Test it NowOutput: Exception in thread "main" java.lang.ArithmeticException: integer overflow at java.lang.Math.subtractExact(Math.java:829) at SubtractExactExample2.main(SubtractExactExample2.java:8) Example 3Test it NowOutput: Exception in thread "main" java.lang.ArithmeticException: long overflow at java.lang.Math.subtractExact(Math.java:849) at SubtractExactExample3.main(SubtractExactExample3.java:8) Next TopicJava Math |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India