1public static void main(String[] args) {
2 int n=12;
3 for(int i=2; i<=n; i++){
4 while(n%i==0){
5 n=n/i;
6 System.out.println(i); //prints 2 2 3
7 }
8 }
9}
1import java.util.Scanner;
2
3public class PrimeFactors {
4 public static void main(String args[]){
5 int number;
6 Scanner sc = new Scanner(System.in);
7 System.out.println("Enter a number ::");
8 number = sc.nextInt();
9
10 for(int i = 2; i< number; i++) {
11 while(number%i == 0) {
12 System.out.println(i+" ");
13 number = number/i;
14 }
15 }
16 if(number >2) {
17 System.out.println(number);
18 }
19 }
20}