package Day04;
import java.util.Scanner;
public class Ex02_Max {
public static void main(String[] args) {
// ์ฒซ ๋ฒ์งธ ์ค์ ์
๋ ฅํ ๊ฐ์ N์ ์
๋ ฅ๋ฐ๊ณ ,
// ๋์งธ ์ค์ N๊ฐ์ ์ ์๋ฅผ ๊ณต๋ฐฑ์ ๋๊ณ ์
๋ ฅ๋ฐ์ผ์์ค.
// N ๊ฐ์ ์ ์ ์ค, ์ต๋๊ฐ์ ๊ตฌํ์์ค.
// (์
๋ ฅ์์)
// 5
// 90 60 70 100 55
// (์ถ๋ ฅ)
// ์ต๋๊ฐ : 100
/*
(์์๋)
1. ์ ์ ํ๋ ์
๋ ฅ๋ฐ์์ N์ ๋์
2. N๊ฐ ์์๋ฅผ ๊ฐ๋ ๋ฐฐ์ด ์ ์ธ ๋ฐ ์์ฑ
3. N๋ฒ ๋งํผ N๊ฐ์ ์ ์ ์
๋ ฅ๋ฐ์์ ๋ฐฐ์ด arr ๋์
4. ๋ฐฐ์ด์ ๋ฐ๋ณตํด์ ์ต๋๊ฐ max ๋ฐฐ์ด์ i๋ฒ์งธ ์์์ ๋น๊ต
5. ๋ ์์ ์ค์์ ๋ ํฐ ์์๋ฅผ max์ ๋์
6. ๋ฐ๋ณต ๋๋๊ณ , max ๋ฅผ ์ถ๋ ฅ
*/
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int arr[] = new int[N];
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
// Integer.MIN_VALUE : -21์ตxxx : int ์ ์ต์๊ฐ
int max = Integer.MIN_VALUE;
for (int i = 0; i < arr.length; i++) {
if( max < arr[i] ) {
max = arr[i];
}
}
System.out.println("์ต๋๊ฐ : " + max);
sc.close();
}
}
Java
๋ณต์ฌ