Page Contents

## Interview Content

- C Programming Coding Questions
- C Pattern Programming Questions
- C Programming Interview Questions
- Java Programming Coding Questions
- Java Pattern Programming Questions
- Java Programming Interview Questions
- Python Programming Coding Questions
- Python Pattern Programming Questions
- Python Programming Interview Questions
- SQL Interview Questions

# Java Program to find Prime Factor of a given number

**Ans: **

In this tutorial you will learn writing Java program to find prime factor of a given program.

Before moving on writing program lets know what is prime factor?

**Read This:** Prime factor program in C

## How this Java program will behave?

The prime factor calculation program will take a number as a input and in result it will print all outputs with prime factors.

**For example** if you want to calculate the prime factor of a number 12 then you should give 12 as an input.

And After calculation program should return 2, 2, 3 as an output.

## Below is a program to find all Prime Factor of a given number in Java

```
import java.util.*;
class Main{
public static void main(String ...args){
int i=0;
Scanner sc= new Scanner(System.in);
System.out.print("please enter a number: ");
int n= sc.nextInt();
System.out.print("Prime factors of a given number \n");
while(n % 2 == 0) {
System.out.print(2+",");
n = n/2;
}
for(i = 3; i <= Math.sqrt(n); i=i+2){
while(n % i == 0) {
System.out.print(i+",");
n = n/i;
}
}
if(n > 2) {
System.out.print(n+",");
}
}
}
```

**Output:**

## Also prepare these Java Programs:

- Write a program in Java to print the Fibonacci series using iterative method.
- Palindrome program in Java using Iterative method
- Java program to find largest of three numbers
- Java program to sum the digits of a number using recursion
- Java program to swap two numbers using third variable
- Java Program to check if two strings are anagrams
- Java program to find largest and smallest number in an array
- Java Program to find top two maximum number in array
- Java Program to remove duplicate elements from an array

##### Latest Uploads on Website

- AVL Tree with explanation
- Radix sort algorithm explanation with example
- Quick Sort Algorithm with explanation
- Bubble sorting algorithm with Bubble sort program in C
- Insertion sort algorithm and program in C
- Selection Sort Algorithm and Program in C
- Linear probing technique explanation with example
- Collision in Hashing and Collision resolution technique
- Hashing in data structure with its types
- Binary search tree operations with Program
- Binary search tree in data structure
- Binary search algorithm in data structure with explanation
- linear search in data structure with Algo and Program