How to Get Max of Two Numbers in Java


Here we may learn how to find maximum of two int, float, double or long numbers using max method of  Math class in Java.

Source Code

package com.beginner.examples;

public class MaxExample {

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

Output:

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