logo

Java 정수 min() 메서드

그만큼 분() Integer 클래스의 메소드입니다. java.lang 패키지 . 이 방법은 두 가지 방법 중 최소값을 수치적으로 반환합니다. 논쟁 사용자가 지정합니다. 이 메서드는 오버로드될 수 있으며 int, double, float 및 long의 인수를 사용합니다.

참고: 양수와 음수가 인수로 전달되면 음수 결과가 생성됩니다. 그리고 두 매개변수가 모두 음수로 전달되면 더 큰 크기의 결과가 생성됩니다.

통사론:

다음은 선언문이다. 분() 방법:

문자 비교 자바
 public static int min(int a, int b) public static long min(long a, long b) public static float min(float a, float b) public static double min(double a, double b) 

매개변수:

데이터 형식 매개변수 설명 필수/선택
정수 사용자가 입력한 숫자 값입니다. 필수의
정수 사용자가 입력한 숫자 값입니다. 필수의

보고:

그만큼 분() 메소드는 사용자가 지정한 두 메소드 인수 중 더 작은 값을 반환합니다.

예외:

저것

호환성 버전:

자바 1.5 이상

실시예 1

 public class IntegerMinExample1 { public static void main(String[] args) { // Get two integer numbers int a = 5485; int b = 3242; // print the smaller number between x and y System.out.println('Math.min(' + a + ',' + b + ')=' + Math.min(a, b)); } } 
지금 테스트해보세요

산출:

 Math.min(5485,3242)=3242 

실시예 2

 import java.util.Scanner; public class IntegerMinExample2 { public static void main(String[] args) { //Get two integer numbers from console System.out.println('Enter the Two Numeric value: '); Scanner readInput= new Scanner(System.in); int a = readInput.nextInt(); int b = readInput.nextInt(); readInput.close(); //Print the smaller number between a and b System.out.println('Smaller value of Math.min(' + a + ',' + b + ') = ' + Math.min(a, b)); } } 

산출:

 Enter the Two Numeric value: 45 76 Smaller value of Math.min(45,76) = 45 

실시예 3

 public class IntegerMinExample3 { public static void main(String[] args) { //Get two integer numbers int a = -70; int b = -25; // prints result with greater magnitude System.out.println('Result: '+Math.min(a, b)); } } 
지금 테스트해보세요

산출:

 Result: -70 

실시예 4

 public class IntegerMinExample4 { public static void main(String[] args) { //Get two integer numbers int a = -20; int b = 25; // prints result with negative value System.out.println('Result: '+Math.min(a, b)); } 
지금 테스트해보세요

산출:

 Result: -20