Computing.Net > Forums > Programming > Prime Number

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Prime Number

Reply to Message Icon

Name: Jaydawg
Date: November 16, 2008 at 01:23:01 Pacific
OS: windows xp
CPU/Ram: celeron m
Product: compaq
Comment:

Hi can any one help me with this code to
"Write a program to determine if the sequence of numbers 11,101,1001,10001…. are all prime numbers up to and including the largest sequence value smaller than the largest integer value represent able on a PC.
This is what i did..
public class PrimeNumberTest
{
public static void main(String a[])
{
int fac=0;

for(int i=2; i<100; i++)
{
for(int j=2; j<=i/2; j++)
{
if(i%j == 0)
fac++;
}

if(fac > 0)
System.out.println(i+ " is Not Prime");
else
System.out.println(i+ " is Prime");

fac=0;
}
}

Hi I'm an MIS Masters student.



Sponsored Link
Ads by Google

Response Number 1
Name: Holla
Date: November 16, 2008 at 22:43:31 Pacific
Reply:

Your program appears like will tell whether numbers between 2 and 100 is a prime. (Though not optimized).

If you are interested in finding whether the sequence 11, 101, 1001, ... etc is prime, change the outer for loop to-


for (i=11,i < 1000000000; i=(i-1)*10+1)

Your series can go upto the maximum number supported by the type of i, that is int, which I guess is dependent on your OS.

--
Holla.


0

Response Number 2
Name: klint
Date: November 17, 2008 at 02:08:00 Pacific
Reply:

You seem to be using Java. Therefore the maximum value of an int is not dependent on your OS. It is 2147483647.

Your problem is how will you be able to check the larger numbers, up to 1000000001, in a reasonable time. If you do it in a naive way, the computation will take a few seconds, but with some thought you can significantly shorten it.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Prime Number

Prime number checking www.computing.net/answers/programming/prime-number-checking/6158.html

Find prime numbers in Java? www.computing.net/answers/programming/find-prime-numbers-in-java/11287.html

Prime Number in MIPS help www.computing.net/answers/programming/prime-number-in-mips-help/13454.html