[JAVA] 이것이 자바다 참조 타입 연습문제 7

반응형

7. 주어진 배열의 항목에서 최대값을 구해보세요(for문을 이용하세요)


실행결과



코드


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class Excercise07_2 {
    public static void main(String[] args) {
        int max = 0;
        int[] array = {1,5,3,8,2};
        
        max = array[0];
        
        for(int i=0; i<array.length; i++) {
            if(max <= array[i]) {
                max = array[i];
            }
        }
        
        System.out.println("max: " + max);
    }
}
 
cs


728x90
반응형