How to Get Min of Two Numbers in Java


The example aims to find minimum of two int, float, double or long numbers by min method in Java.

Source Code

package com.beginner.examples;

public class MinExample {

    public static void main(String[] args){
    	//return minimum of two numbers.
    	System.out.println(Math.min(6 , 6.3));
    	System.out.println(Math.min(6.3 , -12.6));
    	System.out.println(Math.min(6 , -12.6));        
    }
}

Output:

6.0
-12.6
-12.6
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments