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

Programming Example

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

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Website development Company in Allahabad Sarkari Exam Quiz