Home » Java programming language

Java Math Class static int min(int i1 , int i2) with example

Java Math Class static int min(int i1 , int i2) method: Here, we are going to learn about the static int min(int i1 , int i2) method of Math Class with its syntax and example.
Submitted by Preeti Jain, on September 06, 2019

Math Class static int min(int i1 , int i2)

  • This method is available in java.lang package.
  • This method is used to return the minimum one of both the given arguments or in other words this method returns the smallest value of the given two arguments.
  • This is a static method so this method is accessible with the class name too.
  • The return type of this method is int, it returns the smallest element from the given two arguments.
  • This method accepts two arguments of integer (int) types.
  • This method does not throw any exception.

Syntax:

    public static int min(int i1, int i2){
    }

Parameter(s): int i1, int i2 – two integer values, in which we have to find the smallest/minimum value.

Return value:

The return type of this method is int, it returns the smallest/minimum value.

Note:

  • If we pass "NaN" (Not a Number), it returns the same value i.e. "NaN".
  • If we pass zero (-0 or 0), it returns the 0.
  • If we pass the same values in both parameters, it returns the same value.

Java program to demonstrate example of min(int i1,int i2) method

// Java program to demonstrate the example of 
// min(int i1, int i2) method

public class MinDoubleTypeMethod  {
    public static void main(String[] args) {
        // declaring variables
        int i1 = -0;
        int i2 = 0;
        int i3 = -2;
        int i4 = 124;

        // displaying the values
        System.out.println("i1: " + i1);
        System.out.println("i2: " + i2);
        System.out.println("i3: " + i3);
        System.out.println("i4: " + i4);

        // Here , we will get (-2) because we are passing 
        // parameter whose value is (-0,0)
        System.out.println("Math. min(i1,i3): " + Math.min(i1, i3));

        // Here , we will get (0) because we are passing 
        // parameter whose value is (-0,0)
        System.out.println("Math.min(i1,i2): " + Math.min(i1, i2));

        // Here , we will get (0) and we are passing 
        // parameter whose value is (0,124)
        System.out.println("Math.min(i2,i4): " + Math.min(i2, i4));
    }
}

Output

E:\Programs>javac MinDoubleTypeMethod.java

E:\Programs>java MinDoubleTypeMethod
i1: 0
i2: 0
i3: -2
i4: 124
Math. min(i1,i3): -2
Math.min(i1,i2): 0
Math.min(i2,i4): 0





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.