BE/JAVA

[JAVA] 자바 Math.max/min (두 인자 값 중 큰/작은 값 리턴)

veee2 2022. 4. 29. 13:35

Math.max()

- static int max(int a , int b)

- static double max(double a , double b)

- static float max(float a , float b)

- static long max(long a , long b)

max() 함수는 두 인자 값 중 큰 값을 리턴하는 함수이다.


public class MathMaxTest{

    public static void main(String[] args){

        System.out.println( Math.max(26,2) );  // 26
        System.out.println( Math.max(3.1472,1.2) );  // 3.1472
        
    }

}

Math.min()

- static int min(int a , int b)

- static double min(double a , double b)

- static float min(float a , float b)

- static long min(long a , long b)

min() 함수는 두 인자 값 중 작은 값을 리턴하는 함수이다.


public class MathMinTest{

    public static void main(String[] args){

        System.out.println( Math.min(26,2) );  // 2
        System.out.println( Math.min(3.1472,1.2) );  // 1.2

    }

}