Hi, hope you can help me out here. I need to generate all the prime number factors for the number 999999 (3, 7, 11, 13, 37). Here is my algorithm:
step n k comment
------------------------------------------------
0 999999 2 not divisible by 2, k = k + 1
1 999999 3 n is divisible by 3, n = n / 3, print 3
2 333333 3 n is divisible by 3, n = n / 3, print 3
3 111111 3 n is divisible by 3, n = n / 3, print 3
4 37037 3 not divisible by 3, k = k + 1
5 37037 4 not divisible by 4, k = k + 1
6 37037 5 not divisible by 5, k = k + 1
7 37037 6 not divisible by 6, k = k + 1
8 37037 7 n is divisible by 7, n = n / 7, print 7
9 5291 7 not divisible by 7, k = k + 1
10 5291 8 not divisible by 8, k = k + 1
11 5291 9 not divisible by 9, k = k + 1
12 5291 10 not divisible by 10, k = k + 1
13 5291 11 n is divisible by 11, n = n / 11, print 11
14 481 11 not divisible by 11, k = k + 1
15 481 12 not divisible by 12, k = k + 1
16 481 13 n is divisible by 13, n = n / 13, print 13
17 37 13 STOP since 13^2 > 37 print 37
I had no problem generating all the factors for 999999 - but I can't seem to get my isPrime method to work, included below is a copy of my code. It won't compile because apparently I have erros on lines 18 and 33, 18 is the beginning of the isPrime method, and 33 apparently I need a ; but I can't figure out why I could possibly need one there. Hope you all can help me out. Thanks in advance
public class Primenum
{
public static void main (
String[] args)
{
int n=999999;
System.out.println(n+ "'s factors are ");
for (int i = 1; i <= n / 2; i++)
{
if (n % i == 0 && isPrime(i))
{
System.out.print(i+ " ");
}
}
public isPrime()
{
int n=number;
int j;
for (j=2; j<i; j++)
if (j%i != 0)
System.out.print(" ");
j++;
else
j++;
}
}
}