package array;
import java.util.Scanner;
public class Exercise2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); // μ
λ ₯λ°κΈ° μν μ€μΊλ μ€λΉ.
System.out.print("μ μμ κ°μ : ");
int cnt = Integer.parseInt(sc.nextLine()); // μ μμ κ°μ μ
λ ₯ λ°μ.
// nextInt()λ₯Ό μ°μ§ μμ μ΄μ λ μλͺ» μ
λ ₯νμ λ μ€λ₯ λ°μ μν΄.
System.out.print("μ μ " + cnt + "κ° : ");
int[] ar = new int[cnt]; // μμμ λ°μ nκ°μ μ μλ₯Ό λ΄μ arμ΄λΌλ λ°°μ΄ μ μΈ.
for (int i = 0; i < cnt; i++) { // μ
λ ₯ λ°μ μ μμ κ°μλ§νΌ μ μλ₯Ό μ
λ ₯λ°κΈ° μν΄ forλ¬Έ μ¬μ©.
ar[i] = sc.nextInt();
}
int max = ar[0]; // μ΅λκ°μ λ΄μ λ³μ μ μΈ
int min = ar[0]; // μ΅μκ°μ λ΄μ λ³μ μ μΈ
for (int i = 0; i < ar.length; i++) { // λ°°μ΄ μμ μλ μμλ€μ λ°λ³΅λ¬Έμ ν΅ν΄ λΉκ΅ ν κ°κ°μ λ³μ μμ κ° ν λΉ.
if (ar[i] > max) { // μ΅λκ° κ΅¬νλ μ½λ
max = ar[i];
} else if (ar[i] < min) { // μ΅μκ° κ΅¬νλ μ½λ
min = ar[i];
}
}
System.out.println("μ΅μκ° : " + min + ", μ΅λκ° : " + max);
} // main method λ«λ μ€κ΄νΈ
} // class λ«λ μ€κ΄νΈ