์คํธ๋ฆผ์ ๋ฐฐ์ฐ๊ณ ๋ชจ๋ ๊ฒ ์ฌ์์ง ๋
orElse ๋ฌธ ์ ์ฐ๋ฉด Optional int ๋ ์๋ฃํ์ผ๋ก ๋์ด.
์๋๋ฉด ๋ง์ฝ ๋ฐฐ์ด์ด ๋น์ด์์ ๊ฒฝ์ฐ์ ๋ํ ๋์ฒ๋ฅผ ์ ํ๊ธฐ ๋๋ฌธ์ด๋ค.
๋ฐ๋ผ์ orElse(0)๋ฅผ ํด์ค์ผ ์ปดํ์ผ๋ฌ๊ฐ ๋ฏฟ๊ณ int๋ก ๋ณํํด์ค๋ค.
import java.util.Scanner;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] b = new int[N];
for (int i = 0; i < N; i++) {
b[i] = sc.nextInt();
}
int min = IntStream.of(b).min().orElse(0);
int max = IntStream.of(b).max().orElse(0);
System.out.println(min);
System.out.println(max);
}
}
0