Skip to content

Commit d9eb689

Browse files
authored
Create 1.java
1 parent f52578c commit d9eb689

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

20/1.java

+20
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)