백준알고리즘 6단계 1차원배열_java

10818번_최대최소_step01

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] arr = new int[n];
    int max=-1000000;
    int min=1000000;
    for(int i=0;i<n;i++)
    {
      arr[i] = sc.nextInt();
      if(max < arr[i])
      {
        max = arr[i];
      }
      if(min > arr[i])
      {
        min = arr[i];
      }
    }
    System.out.println(min+" "+max);
  }
}


2562번_최댓값_step02

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int[]  arr=new int[9];
        int max=0, index=0;
        for(int i=0;i<9;i++)
        {
            arr[i]=sc.nextInt();
             if(arr[i]>max){
                max = arr[i];
                index = i;
            }
        }

        System.out.println(max);
        System.out.println(index+1);

    }
}


2577번_숫자의 개수_step03

1