- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Prime factors in java

**Factor****s** are the numbers we multiply to get another number.

factors of 14 are 2 and 7, because 2 × 7 = 14.

Some numbers can be factored in more than one way.

16 can be factored as 1 × 16, 2 × 8, or 4 × 4.

A number that can only be factored as 1 times itself is called a **prime number**.

The first few primes are 2, 3, 5, 7, 11, and 13.

The list of all the prime-number factors of a given number is the **prime factors** of a number. The factorization of a number into its prime factors and expression of the number as a product of its prime factors is known as the **prime factorization** of that number. The** prime factorization** of a number includes ONLY the prime factors, not any products of those prime factors.

## Program

import java.util.Scanner; public class PrimeFactors { public static void main(String args[]){ int number; Scanner sc = new Scanner(System.in); System.out.println("Enter a number ::"); number = sc.nextInt(); for(int i = 2; i< number; i++) { while(number%i == 0) { System.out.println(i+" "); number = number/i; } } if(number >2) { System.out.println(number); } } }

## Output

Enter a number 24 2 2 2 3

- Related Questions & Answers
- Prime factors of a big number in C++
- Maximum number of unique prime factors in C++
- Find all prime factors of a number - JavaScript
- Java Program to find Product of unique prime factors of a number
- Print all prime factors and their powers in C++
- Prime factors of LCM of array elements in C++
- Count common prime factors of two numbers in C++
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X in C++
- How to find prime factors of a number in R?
- Product of unique prime factors of a number in Python Program
- Python Program for Product of unique prime factors of a number
- C Program for efficiently print all prime factors of a given number?
- Count numbers from range whose prime factors are only 2 and 3 in C++
- C/C++ Program to find Product of unique prime factors of a number?
- Java program to check for prime and find next Prime in Java

Advertisements