We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 21bd91a commit d41fc15Copy full SHA for d41fc15
Maths/PrimeFactorization.java
@@ -0,0 +1,35 @@
1
+package Maths;
2
+
3
+import java.lang.Math;
4
+import java.util.Scanner;
5
6
+public class algorithm {
7
+ public static void main(String[] args){
8
+ System.out.println("## all prime factors ##");
9
+ Scanner scanner = new Scanner(System.in);
10
+ System.out.print("Enter a number: ");
11
+ int n = scanner.nextInt();
12
+ System.out.print(("printing factors of " + n + " : "));
13
+ pfactors(n);
14
+ }
15
+ public static void pfactors(int n){
16
17
+ while (n%2==0)
18
+ {
19
+ System.out.print(2 + " ");
20
+ n /= 2;
21
22
23
+ for (int i=3; i<= Math.sqrt(n); i+=2)
24
25
+ while (n%i == 0)
26
27
+ System.out.print(i + " ");
28
+ n /= i;
29
30
31
32
+ if(n > 2)
33
+ System.out.print(n);
34
35
+}
0 commit comments