Java Math.addExact() method21 Mar 2025 | 1 min read The java.lang.Math.addExact() returns the sum of its arguments. It will throw an exception if the result overflows either int or long. SyntaxParameterReturn
Example 1Output: 1206 Example 2Output: -738 Example 3Output: Exception in thread "main" java.lang.ArithmeticException: integer overflow at java.lang.Math.addExact(Math.java:790) at AddExactExample3.main(AddExactExample3.java:8) Example 4Output: Exception in thread "main" java.lang.ArithmeticException: long overflow at java.lang.Math.addExact(Math.java:809) at AddExactExample4.main(AddExactExample4.java:8) Next TopicJava Math |
Java method The java.lang. is used to return the trigonometric cosine of an angle. This method returns value between -1 to 1. Syntax public static double cos(double a) Parameter a = an angle, in radians Return It returns the cosine value of the argument. If the argument is positive or negative number,...
2 min read
Java method The java.lang. method returns the absolute (Positive) value of a int value. This method gives the absolute value of the argument. The argument can be int, double, long and float. Syntax: public static int abs(int i) public static double abs(double d) public static float abs(float f) public static...
2 min read
Java Method In the realm of Java programming, randomness plays a crucial role in various applications, ranging from simulations and gaming to cryptography and statistical analysis. Java offers several tools to generate random numbers, among which the method stands out as a simple yet...
3 min read
Java method The java.lang. is used to return the hyperbolic cosine of a value. The hyperbolic cosine of any value x can be defined as (ex + e -x)/2, where e is an Euler's number. Syntax public static double cosh(double x) Parameter x = the number whose hyperbolic cosine...
2 min read
Java method The java.lang. is used to return the trigonometric sine of an angle. This method returns value between -1 to 1. Syntax public static double sin(double a) Parameter a = an angle, in radians Return It returns the sine value of the argument. If the argument is positive or negative number,...
2 min read
Java () method The java.lang.() is a built-in math function in java which is used to convert an angle measured in radians to an approximately equivalent angle measured in degrees. Syntax public static double toDegrees(double x) Parameter x = an angle, in radians Return It returns the measurement of the angle x...
2 min read
Java method The java.lang. returns the difference of the arguments. It will throw an exception if the result overflows either int or long. Syntax public static int subtractExact(int a, int b) public static long subtractExact(long a, long b) Parameter a = the first value b = the second value to...
2 min read
Java Math.Up() Method The java.lang.Math.Up() is a inbuilt math method in java. It returns the floating-point value adjacent to the user specified parameter (d) in the direction of positive infinity. This method is equivalent to After(d, Double.POSITIVE_INFINITY) method. Implementation of Up may run faster than its equivalent...
2 min read
Java method The java.lang.Math.mutliplyExact() returns the product of the arguments. It will throw an exception if the result overflows either int or long. Syntax public static int multiplyExact(int a, int b) public static long multiplyExact(long a, long b) public static long multiplyExact(long a, int b) Parameter a = the first...
2 min read
Java method The java.lang. is used to find the largest integer value that is less than or equal to the algebraic quotient. This method first divide the first argument by the second argument and then performs a floor() operation over the result and returns the...
2 min read
We request you to subscribe our newsletter for upcoming updates.
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