본문 바로가기

Java/Java 알고리즘 인프런

ArrayList에서 max와 min값만 빼기

반응형
ArrayList<Integer> list = new ArrayList<>();
    list.add(0, 3);
    list.add(1, 4);
    list.add(2, 5);
    list.add(3, 100);
    list.add(4, 1);
    int max=Integer.MIN_VALUE;
    int min=Integer.MAX_VALUE;
        for(int x:list) {
            min=Math.min(x, min);
            max=Math.max(max, x);
}
    list.remove(list.indexOf(max));
    list.remove(list.indexOf(min));
    for(int x:list) {
        System.out.print(x+" ");
}
반응형

'Java > Java 알고리즘 인프런' 카테고리의 다른 글

자료구조 출력  (0) 2022.05.26
[Java] 반올림 올림 버림  (0) 2022.05.24
String[]을 String[][]로 변환  (0) 2022.05.21
[Ch.05 - StackQueue] 08. 응급실 #  (0) 2022.05.20
[Ch.05 - StackQueue] 07. 교육과정 설계  (0) 2022.05.20