forked from tusharjuneja06/simplejavaprogram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeFactorization.java
More file actions
26 lines (24 loc) · 793 Bytes
/
PrimeFactorization.java
File metadata and controls
26 lines (24 loc) · 793 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
import java.io.*;
public class PrimeFactorization{
public static void primeFactors(int num){
int number=num;
if(number<=1)
return;
for(int counter=2;(counter*counter)<=number;counter++){
while(number%counter==0){
System.out.print(counter+" ");
number=number/counter;
}
}
if(number>0){
System.out.print(number+" ");
}
}
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter an integer: ");
int n = Integer.parseInt(br.readLine());
System.out.print("The Prime Factors of "+n+" are: ");
primeFactors(n);
}
}