망나니 AWOS의 일상
article thumbnail

1단계 10818번 최소, 최대

import java.util.Scanner;
import java.util.Arrays;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int[] arr = new int[n];
        
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
        
		Arrays.sort(arr);
		System.out.print(arr[0] + " " + arr[n - 1]);
    }
}

 

2단계 2562번 최댓값

import java.util.Scanner;

class Main {
    public static void main(String []args) {
        Scanner sc = new Scanner(System.in);
        int arr[] = new int[9];
        int max =0, count=0;
        
        for(int i=0; i<arr.length; i++){
            arr[i] = sc.nextInt();
            
            // 최댓값, 위치 구하기
            if(max < arr[i]) {
                max = arr[i];
                count=i+1;
            }
        }
        System.out.println(max);
        System.out.println(count);
    }
}

 

3단계 2577번 숫자의 개수

import java.util.Scanner;
// import java.util.Arrays;

class Main {

    public static void main(String []args) {
        Scanner sc = new Scanner(System.in);
        int result = 1, mod=0;
        // 0~9까지 체크하기 위해서 배열 생성
        int[] arr = new int[10];

        for(int i=0; i<3; i++) {
            int n=sc.nextInt();
            result = result * n;
        }

        while(result>0) {
            // mod의 값이 중복, 0~9까지 원소의 개수를 알 수 있음
            mod = result%10;
            arr[mod]++;
            result/=10;
        }

        for(int j : arr)
            System.out.println(j);
    }
}

3단계 문제... 1시간 고민한 것 같습니다.

profile

망나니 AWOS의 일상

@AWOS

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!