Java Math min() Function
Java Math Class
Here, in the page we will discuss about the min() Function in java.
Java Math class provides several methods to perform several operations on math calculations like max(), min(), sin(), cos(), round(), ceil(), floor(), copySign() etc. The java.lang.Math class contains various methods for performing basic numeric operations
Java min Function :
Java Collection contains Math class and The class Math contains methods for performing several basic and advance numeric operations such as the exponential, logarithm, square root, and trigonometric functions.
The min() method takes two arguments, say num1 and num2, and returns the minimum between two of them. The arguments can be of int, double, float and long type.
Syntax:
Math.min(number1,number2);
Definition of Parameters:
Return Type :
Example :
import java.util.*; public class Main{ public static void main(String[] args) { int num1 = 9; int num2 = 2; // Printing Minimum between 2 Inputs System.out.println("Minimum of two Elements is : " + Math.min(num1,num2)); } }
Output:
Minimum of two Elements is : 2
Explanation:
In the above Example, We had taken two Integer values. The min Function returns the minimum between two of the inputs.
Example for Different Data Values:
import java.util.*; public class Main{ public static void main(String[] args) { // Integer arguments int num1 = 3; int num2 = 1; System.out.println("Minimum in Integers Values : " + Math.min(num1, num2)); // Long arguments long num3 = 47831L; long num4 = 852224L; System.out.println("Minimum in Long Values : " + Math.min(num3, num4)); // Float arguments float num5 = 7.6f; float num6 = 2.8f; System.out.println("Minimum in Float Values : " + Math.min(num5, num6)); // Double arguments double num7 = 13.4d; double num8 = 21.01d; System.out.println("Minimum in Double Values : " + Math.min(num7, num8)); } }
Output:
Minimum in Integers Values : 1 Minimum in Long Values : 47831 Minimum in Float Values : 2.8 Minimum in Double Values : 13.4
Explanation:
In the above Example, We had taken two arguments of Integer, Long, Float and double values. The min function returns the minimum value between two of the arguments.
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment