We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f52578c commit d9eb689Copy full SHA for d9eb689
20/1.java
@@ -0,0 +1,20 @@
1
+import java.util.*;
2
+
3
+class Main {
4
+ // 소수 판별 함수(2이상의 자연수에 대하여)
5
+ public static boolean isPrimeNumber(int x) {
6
+ // 2부터 x의 제곱근까지의 모든 수를 확인하며
7
+ for (int i = 2; i <= Math.sqrt(x); i++) {
8
+ // x가 해당 수로 나누어떨어진다면
9
+ if (x % i == 0) {
10
+ return false; // 소수가 아님
11
+ }
12
13
+ return true; // 소수임
14
15
16
+ public static void main(String[] args) {
17
+ System.out.println(isPrimeNumber(4));
18
+ System.out.println(isPrimeNumber(7));
19
20
+}
0 commit comments