(기초)그래서 뭘 배운거야?/Java
JV-65-API-Operator : 매개변수 있고, 리턴 값 있고, apply~() 추메 가진 연산 인페
Soheny.P
2021. 11. 18. 17:42
728x90
import java.util.function.IntBinaryOperator;
public class Ex08Operator {
//Operation
/*
- Operation 인터페이스는 매개변수와 리턴값이 존재하고, apply~~() 메소드를 가짐
- 메소드들은 매개값 이용해 연산 하고, 동일 타입으로 리턴값 제공하는 역할ㅇ
*/
private static int[] score = {92, 87, 75};
public static int maxOrMin(IntBinaryOperator op) {
int result = score[0];
for (int i : score) {
result = op.applyAsInt(result, i);
}
return result;
}
public static void main(String[] args) {
int max = maxOrMin((a, b) -> (a>=b)?a:b);
System.out.println("최대값 : "+max);
int min = maxOrMin((a, b) -> (a<=b)?a:b);
System.out.println("최소값 : "+min);
}
}
728x90