The java.lang.Math.subtractExact() is a built-in math function in java which returns the difference of the
arguments.It throws an exception if the result overflows a long.As subtractExact(long x, long y) is static,
so object creation is not required.
public static long subtractExact(long x, long y) Parameter : x : the first value y : the second value to be subtracted from the first Return : This method returns the difference of the arguments. Exception : It throws ArithmeticException - if the result overflows a long.
Example :To show working of java.lang.Math.subtractExact() method.
Runtime Error : Exception in thread "main" java.lang.ArithmeticException: long overflow at java.lang.Math.subtractExact(Math.java:849) at Gfg2.main(File.java:13)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
In case you wish to attend live classes with industry experts, please refer Geeks Classes Live