# Prime Factor Calculator Java Program

Apple iPhone 5 (Latest Model) – 16GB – White & Silver (Factory Unlocked)…
Current Bid: \$525.99

Furthermore, Prime Factors are factors of a number, which only compose of prime numbers. To check if the prime factors of a number is correct, the product of the factors should be equal to the number itself.

For example:

Look for the prime factor of 20:

Possible factors for 20 are:

2, 5, 2

10, 2

1, 20

The correct prime factors of 20 are 2, 5, 2 because they are all prime numbers opposite to 10, 2 and 1, 20.

Another Example:

Look for the Prime Factors of 50:

Possible Factor:

50, 1

10, 5

2, 5, 5

Correct Prime Factors are: 2, 5, 5

You can experiment to look for prime factors by running the below Java Program to your Java Development kit.

Unlocked F668 Cool Super Sports car Cell phone Touch screen Dual SIM JAVA Blue
Current Bid: \$26.00
Samsung Galaxy S 4 SPH-L720 (Latest Model) – 16GB – White Frost (Sprint)…
Current Bid: \$392.00

Prime factor calculator Java Program

Prime numbers are numbers that are only divisible by itself like 2, 3, 5, 7, 13 and so on. Note that Prime numbers are different to odd numbers. All the prime numbers are odd numbers but not all odd numbers are prime numbers.

What is the Program Algorithm?

First it will check if the number is an even number by assigning a variable i to 2,then continue to check it as it increment by 1. If it is an even number, it will continuously divide the number to the incrementing variable i until the number is not divisible to any number equal or less than to the half of the entered number. This is to make sure that the numbers are all prime numbers. See the sample code below and run it for better understanding.

## Sample Source Code for Prime Factor Calculator

package primefactor;
import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
int num;
Scanner input = new Scanner(System.in);
System.out.print(“Enter a number: “);
num = input.nextInt();
System.out.print(“Prime Factor/s of “+ num + “: “);
for(int i=2; i<=num; i++) { if(num%i == 0) { num = num/i; System.out.print(i + " "); i--; } } System.out.println(); } }

## Related Java Tutorials:

5 Important Tips to Learn Java Programming and Other Programming Languages
Basic Knowledge Required in Programming
How to Program in Java Using Netbeans: Complete Simple Easy Steps
Java Simple Codes for Beginners
Java Tutorial for Beginners: A Beginners Guide on Learning Java Programming
Java Tutorial Examples

## Java Video Tutorial:

Java Programming Video Training tutorials CBT 30+ Hrs
Current Bid: \$4.99
Advanced Java Programming Video Training tutorials CBT – 30+ Hrs – Master level
Current Bid: \$4.99

## Java Books

Head First Java, 2nd Edition, Kathy Sierra, Bert Bates, Sierra Kathy, Bates Be
Current Bid: \$19.14
Data Structures and Algorithm Analysis in Java by Mark A. Weiss 3rd ,3e 3ed
Current Bid: \$46.48

## Other Java Source Codes:

Java Program: How to Use If Statement in Java Programming
Java Program: Using Multi If and Else Statement in Java Programming
Java Program: How to Use If-Else Statement in Java Programming
Java Source code sample: How to Add Numbers inside an Array using For Loop
Java Program: How to Use Switch Statement in Java
Java Program: How to Parse a String into Integer in Java Programming
Java Program: Count the Number of String Characters in Java
Java Program: Reverse String in Java Using For Loop
Java Program: Palindrome Test Java Source Code
Java Program: How to Sort Numbers in an Array in a Descending Order
Java Program: How to Sort Numbers in Ascending Order
Sample Java Program for String Tokenizer
Sample Program for JOptionpane and Java Source Code for Basic Calculator
What is a Java Scanner Class and How to Use it?
What is MDAS? Sample Java Source Code for MDAS
What is a Static Method in Java?
Casting in Java