We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1790948 commit f720bc3Copy full SHA for f720bc3
JavaBook/NumberThoery/PrimeFactors.java
@@ -0,0 +1,33 @@
1
+public class PrimeFactors {
2
+ public static void primeFactors(int n){
3
+ for(int i=2; i<=Math.sqrt(n);i++){
4
+ while(n%i==0){
5
+ System.out.print(i+" ");
6
+ n=n/i;
7
+ }
8
9
+ if(n>1){
10
+ System.out.print(n+" ");
11
12
13
+ public static boolean isPrime(int n){
14
+ if(n<=1){
15
+ return false;
16
17
+ for(int i=2;i<=Math.sqrt(n);i++){
18
+ if(n%i==0)
19
20
21
+ return true;
22
23
+ public static void main(String args[]){
24
+ int n = 125;
25
+ primeFactors(n);
26
+ System.out.println();
27
+ if(isPrime(n)){
28
+ System.out.println(n + " is a prime number.");
29
+ }else{
30
+ System.out.println(n + " is not a prime number.");
31
32
33
+}
0 commit comments