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}
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}
1public class Factors {
2
3 public static void main(String[] args) {
4
5 int number = 60;
6
7 System.out.print("Factors of " + number + " are: ");
8 for(int i = 1; i <= number; ++i) {
9 if (number % i == 0) {
10 System.out.print(i + " ");
11 }
12 }
13 }
14}
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}