- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
Factors 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 Articles
- What are prime factors?
- Write the prime factors of 18.
- Java Program to find Product of unique prime factors of a number
- Prime factors of a big number in C++
- Maximum number of unique prime factors in C++
- Express 625 as exponents of prime factors.
- Prime factors of LCM of array elements in C++
- Print all prime factors and their powers 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++
- Find all prime factors of a number - JavaScript
- How to find prime factors of a number in R?
- Find all the prime factors of 1729 and arrange them in ascending order. Now state the relation, if any; between two consecutive prime factors.
- Factorise the following number into its prime factors. 765
- Express 429 as a product of its prime factors.

Advertisements