본문 바로가기
Language/JAVA

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

by 썸머워즈 2019. 6. 12.
반응형

- Math.max/min 메서드 사용 (두 값중 크거나 작은 값 리턴) -


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() 함수는 두 인자 값 중 큰 값을 리턴하는 함수이다.


예제 1) Math.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() 함수는 두 인자 값 중 작은 값을 리턴하는 함수이다.


예제 2) Math.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

    }
}
반응형


댓글

TOP