DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

# Thread: Creating Prime Number command

1. Registered User
Join Date
Aug 2006
Posts
3

## Creating Prime Number command

I am currently tring to creat a prime number java code. However, every time I put the infinity symbol (∞) it says

"C:\java\prime.java:15: cannot find symbol
symbol : variable ì
location: class prime
prime = (number1)/ì ;
^
1 error"

PHP Code:
 // make prime numbers up to infinity class prime  {   public static void main (String args[]) {     int number1, prime;     int lower, upper, step;     lower = 0;      // lower limit of table     upper = 1;  // upper limit of table     step  = 1;     // step size     for (number1=lower; number1 > upper; number1 = number1 + step) {       prime = (number1)/&#8734; ;       System.out.println(number1 + " " + prime);     } // for loop ends here   } // main ends here }  

Please inform me of my mistakes. Can some one please make a prime number command for me to learn? (using the infinity symbol)

2. Registered User
Join Date
Aug 2003
Posts
313
There is no place where you define that symbol. Why not just use Integer.MAX_VALUE for infinity.

3. Registered User
Join Date
Aug 2006
Posts
3
like this?

UPDATE: FIXED

PHP Code:
 // make prime number class prime  {   public static void main (String args[]) {     int number1, prime;     int lower, upper, step;     int x;     x = Integer.MAX_VALUE;     lower = 0;      // lower limit of table     upper = 1;  // upper limit of table     step  = 1;     // step size     for (number1=lower; number1 > upper; number1 = number1 + step) {       prime = (number1)/x;       System.out.println(number1 + " " + prime);     } // for loop ends here   } // main ends here }  

This doesnt seem to work. There are no errors anymore but now after I start the java code, nothing shows up. Help!

-
Last edited by 999_madcows; 08-10-2006 at 03:18 PM.

4. Registered User
Join Date
Aug 2003
Posts
313
Your loop conditional is inverted. You are saying number1 > upper rather than number1 < upper.

Hope this helps.

5. Registered User
Join Date
Aug 2006
Posts
3
alright, i changed it to number1 < upper. now the outcome is

"0 0"

that is not what I want. How can I make it so it shows a list of prime numbers to infinity?

6. Senior Member
Join Date
Dec 2004
Location
San Bernardino County, California
Posts
1,468
Looks as if it is working to me, since the "upper limit" of your table is one and you are telling your loop to stay below the upper limit.

Have you done any research on the methods of calculating prime numbers? Will your formula do what you want? You are using "int" for your value storage. You are going to exhaust your ability to refer to prime numbers pretty quickly.

#### Posting Permissions

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

 FAQ Latest Articles Java .NET XML Database Enterprise