-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
37 lines (29 loc) · 855 Bytes
/
Copy pathMain.java
File metadata and controls
37 lines (29 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.util.Scanner;
class AsalCarpanlar {
public static boolean asalMi(int sayi) {
if (sayi < 2) {
return false;
}
for (int i = 2; i <= Math.sqrt(sayi); i++) {
if (sayi % i == 0) {
return false;
}
}
return true;
}
public static void asalCarpanlar(int sayi) {
System.out.print(sayi + " sayısının asal çarpanları: ");
for (int i = 2; i <= sayi; i++) {
while (sayi % i == 0 && asalMi(i)) {
System.out.print(i + " ");
sayi /= i;
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Bir sayı girin: ");
int sayi = scanner.nextInt();
asalCarpanlar(sayi);
}
}