본문 바로가기
Java/알고리즘

[Java] 백준 1978번 : 소수 찾기

by EricJeong 2019. 9. 5.

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int answer = 0;

		int[] nums = new int[N];
		for (int i = 0; i < N; i++) {
			nums[i] = in.nextInt();
			if(check(nums[i])) {
				answer++;
			}
		}
		
		System.out.println(answer);
		
	}
	
	static boolean check(int num) {
		boolean result = true;
		
		if(num < 2) {
			result = false;
		}
		
		for(int i=2; i<num; i++) {
			if(num % i == 0) {
				result = false;
			}
		}
		
		
		
		return result;
	}
}

댓글