Programming/BaekJoon

백준 10818번 최소, 최대

helloworld: 2021. 7. 16. 12:57

public class 최소최대 {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    br.readLine();
    StringTokenizer st = new StringTokenizer(br.readLine());

    //최소값, 최대값
    int max = -1000001;
    int min = 1000001;

    while(st.hasMoreTokens()) {
      int x = Integer.parseInt(st.nextToken());

      if(x > max) {
        max = x;
      }
      if(x < min) {
        min = x;
      }
    }

    System.out.printf("%d %d", min, max);
  }
}