1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
/* Find minimum of two numbers using Math.min This java example shows how to find minimum of two int, float, double or long numbers using min method of Java Math class. */ public class FindMinimumOfTwoNumbersExample { public static void main(String[] args) { /* * To find minimum of two int values, use * static int min(int a, int b) method of Math class. */ System.out.println(Math.min(34,45)); /* * To find minimum of two float values, use * static float min(float f1, float f2) method of Math class. */ System.out.println(Math.min(43.34f, 23.34f)); /* * To find minimum of two double values, use * static double min(double d2, double d2) method of Math class. */ System.out.println(Math.min(4324.334, 3987.342)); /* * To find minimum of two long values, use * static long min(long l1, long l2) method of Math class. */ System.out.println(Math.min(48092840,4230843)); } } /* Output would be 34 23.34 3987.342 4230843 */ |
In your example of min for long arguments, the arguments are really ints, thus Math.min(int,int) is called instead of Math.min(long,long). The following would be correct:
/*
* To find minimum of two long values, use
* static long min(long l1, long l2) method of Math class.
*/
System.out.println(Math.min(48092840L,4230843L));