The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

there are two ways.

Posted by swapnil on November 15, 2000 at 9:01 AM

hello,
the first way :
...........................................................import java.math.*;
public class test
{
public static void main(String[] args)
{
BigInteger bi=new BigInteger("11098098091");
boolean b=bi.isProbablePrime(1);
System.out.println(b);
}
}
...............................................................

The second way :
Follow the steps and generate the code.
1. let the no. be x
2. take the (positive value) square-root of x and store it in y.
3. y may be a whole no. or a no. with decimals in it.
4. now ceil() this y and store the result in z
5. now test whether the original no. i.e.x is divisible by any one of the no.s from 3 to z (excluding all the even nos. in between).
6. if yes then the no. is NOT prime.
7. if no then the no. is DEFINITELY prime.
..............................................................

hope this solves ur problem
regards,
swapnil





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us