1. Member
Join Date
Feb 2009
Posts
3
Rep Power
0

## help needed

Hi friends i'm new to java
and i need help to write program that will find prime factors of a given number by using methods

2. Member
Join Date
Feb 2009
Location
Delhi
Posts
63
Rep Power
0
Originally Posted by amarchandar
Hi friends i'm new to java
and i need help to write program that will find prime factors of a given number by using methods
hi..
your question is not dependent on the java... first develop a logic... for that use ur paper and pen.. then try to implement into java.

then, if you find any prob then raise the query.

3. Originally Posted by amarchandar
Hi friends i'm new to java
and i need help to write program that will find prime factors of a given number by using methods
What you have done so far? Try to workout something first lol. Then ask your question more clearly, where you stuck is.

4. I have just recently made a factor-related program. I'll show you a few methods that I have from it:
Java Code:
```private int[] getFactors(int number) {
ArrayList<Integer> factorList = new ArrayList<Integer>();
int numOfFactors = 0;
Integer[] factors;
for(int i = 1; i <= number; i++) {
if(i % number == 0) {
numOfFactors++;
}
}
factorList.trimToSize();
if(numOfFactors == 2) isPrime = true;
else isPrime = false;
factors = new Integer[factorList.size()];
return integerArrayToIntArray(factorList.toArray(factors));
}```
This gets a numbers factors(doesn't just get the prime ones) but I have another method that gets all the prime numbers from start to end arguments :
Java Code:
```public int[] getPrimeNumbers(int start, int end) {
boolean b = isPrime;
for(int i = start; i <= end; i ++) {
getFactors(i);
if(isPrime) {
}
}
isPrime = b;
}```
Maybe those will help you get started, look over and see how I did it. Then write your own that only gets prime factors (do NOT just copy and paste mine). Hope this helps.
-MK12

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•