Programming Examples

Java program to input a number and print all its prime factors using prime factorization


Write a program to input a number and print all its prime factors using prime factorization.

For Example,

INPUT: Enter an integer: 24

OUTPUT: Prime Factors using Prime Factorisation are:

2223

Solution

import java.util.*;
class Factorization
{
	public static void main(string arr[])
	{
		Scanner sc=new Scanner(System.in);
		int n,f=2;
		System.out.println(“Enter a number:”);
		n=sc.nextInt();
		while(n>1)
		{
			if(n%f==0)
			{
				System.out.println(f);
				n=n/f;
			}
			else
				f++;
		}
	}
}
Output

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad