forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1.java
More file actions
20 lines (18 loc) Β· 615 Bytes
/
1.java
File metadata and controls
20 lines (18 loc) Β· 615 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.util.*;
class Main {
// μμ νλ³ ν¨μ(2μ΄μμ μμ°μμ λνμ¬)
public static boolean isPrimeNumber(int x) {
// 2λΆν° xμ μ κ³±κ·ΌκΉμ§μ λͺ¨λ μλ₯Ό νμΈνλ©°
for (int i = 2; i <= Math.sqrt(x); i++) {
// xκ° ν΄λΉ μλ‘ λλμ΄λ¨μ΄μ§λ€λ©΄
if (x % i == 0) {
return false; // μμκ° μλ
}
}
return true; // μμμ
}
public static void main(String[] args) {
System.out.println(isPrimeNumber(4));
System.out.println(isPrimeNumber(7));
}
}