본문 바로가기
알고리즘 & 자료구조/프로그래머스

최대값과 최솟값

by 신재권 2022. 12. 25.
package programmers;

public class 최대값과최솟값 {

   public static String solution(String s) {
      String[] strings = s.split(" ");
      int max = Integer.MIN_VALUE;
      int min = Integer.MAX_VALUE;
      for (String string : strings) {
         int number = Integer.parseInt(string);
         max = Math.max(max, number);
         min = Math.min(min, number);
      }

      return min + " " + max;
   }

   public static void main(String[] args) {
      System.out.println(solution("1 2 3 4"));
      System.out.println(solution("-1 -2 -3 -4"));
      System.out.println(solution("-1 -1"));
   }
}

'알고리즘 & 자료구조 > 프로그래머스' 카테고리의 다른 글

최솟값 만들기  (0) 2022.12.27
JadenCase 문자열 만들기  (0) 2022.12.26
크기가 작은 부분 문자열  (0) 2022.12.24
햄버거 만들기  (0) 2022.12.23
문자열 나누기  (1) 2022.12.22