public class TestPrime
class TestRange extends Thread
1: //TestPrime.java
2: //From van der Linden
3:
4: public class TestPrime
5: {
6:
7: public static void main(String s[])
8: {
9: long possPrime = Long.parseLong(s[0]);
10: int centuries = (int)(possPrime/100) +1;
11: for(int i=0;i<centuries;i++)
12: new TestRange(i*100, possPrime).start();
13: }
14: }
15:
16: ////////////////////////////////////////////
17:
18: class TestRange extends Thread
19: {
20: static long possPrime;
21: long from, to;
22:
23: // constructor
24: // record the number we are to test, and
25: // the range of factors we are to try.
26: TestRange(int argFrom,long argpossPrime)
27: {
28: possPrime=argpossPrime;
29: if (argFrom==0) from=2; else from=argFrom;
30: to=argFrom+99;
31: }
32:
33: public void run()
34: {
35: for (long i=from; i<=to && i<possPrime; i++)
36: {
37: if (possPrime % i == 0)
38: {// i divides possPrime exactly
39: System.out.println(
40: "factor "+i+" found by thread "+getName());
41: break; // get out of for loop
42: }
43: yield();
44: }
45: }
46: }