Java Math.toIntExact() method21 Mar 2025 | 1 min read 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 |
Java method The java.lang. is used to round the argument to nearest mathematical integer. Syntax public static double rint(double x) Parameter x= a double value Return It returns closest floating-point value to x that is equal to a mathematical integer. If the argument is positive or negative number, this method will return...
2 min read
Java method The Java.lang.math.min() is an inbuilt method in Java which is used to return Minimum or Lowest value from the given two arguments. The arguments are taken in int, float, double and long. Syntax: public static int min(int a, int b) public static double min(double a, double...
2 min read
Java method The java.lang. is used to return the square root of a number. Syntax public static double sqrt(double x) Parameter x= a value Return This method returns the square root of x. If the argument is positive double value, this method will return the square root of a given value. If the...
2 min read
Java method The java.lang. is used to return the Euler's number e raised to the power of a double value and subtract one form it. Here, e is an Euler's number and it is approximately equal to 2.718281828459045. Syntax public static double expm1(double x) Parameter x = It is...
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 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. is used to calculate the trigonometric Arc Cosine of an angle. Arc cosine is also called as inverse of a cosine. This method returns the values between 0.0 and pi. Syntax public static double acos(double a) Parameter a = the value whose arc cosine is...
2 min read
Java method The Java.lang.math.max() is an inbuilt method in Java which is used to return Maximum or Largest value from the given two arguments. The arguments are taken in int, float, double and long. Syntax: public static int max(int a, int b) public static double max(double a, double...
2 min read
Java method The java.lang. returns the negation of the argument. It will throw an exception if the result overflows either int or long. Syntax public static int negateExact (int a) public static long negateExact (long a) Parameter a = the value to negate Return It returns the negation of the argument. If...
2 min read
Java method The java.lang. is used to find out the Logarithmic of a number when the base is 10. This method returns the base 10 logarithm of a double value. Syntax public static double log10(double x) Parameter x= a value entered by user Return This method returns the base 10 logarithm...
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