그만큼 java.lang.math.max() 함수는 최대 2개의 숫자를 반환하는 Java의 내장 함수입니다. 인수는 int, double, float 및 long으로 사용됩니다. 음수와 양수가 인수로 전달되면 양수 결과가 생성됩니다. 그리고 전달된 두 매개변수가 모두 음수이면 크기가 더 작은 숫자가 결과로 생성됩니다.
통사론:
문자를 int로 자바
dataType max(dataType num1, dataType num2) The datatypes can be int, float, double or long. Parameters : The function accepts two parameters num1 and num2 among which the maximum is returned>
반환 값: 이 함수는 최대 2개의 숫자를 반환합니다. 데이터 유형은 인수의 데이터 유형과 동일합니다.
아래는 max() 함수의 예입니다.
// Java program to demonstrate the use of max() function> // when two double data-type numbers are> // passed as arguments> public> class> Gfg {> > >public> static> void> main(String args[])> >{> >double> a =>12.123>;> >double> b =>12.456>;> > >// prints the maximum of two numbers> >System.out.println(Math.max(a, b));> >}> }> |
>
>
산출:
파이썬 프로그램 예제
12.456>
while 루프 자바를 수행
// Java program to demonstrate the use of max() function> // when one positive and one negative> // integers are passed as argument> public> class> Gfg {> > >public> static> void> main(String args[])> >{> >int> a =>23>;> >int> b = ->23>;> > >// prints the maximum of two numbers> >System.out.println(Math.max(a, b));> >}> }> |
>
>
산출:
23>
java do while 예제
// Java program to demonstrate the use of max() function> // when two negative integers are passed as argument.> public> class> Gfg {> > >public> static> void> main(String args[])> >{> >int> a = ->25>;> >int> b = ->23>;> > >// prints the maximum of two numbers> >System.out.println(Math.max(a, b));> >}> }> |
>
>
산출:
-23>