DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Creating Prime Number command

  1. #1
    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"


    The code that I created was this:


    PHP Code:
    // make prime numbers up to infinity

    class prime  {

      public static 
    void main (String args[]) {

        
    int number1prime;
        
    int lowerupperstep;

        
    lower 0;      // lower limit of table
        
    upper 1;  // upper limit of table
        
    step  1;     // step size

        
    for (number1=lowernumber1 uppernumber1 number1 step) {
          
    prime = (number1)/∞ ;
          
    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. #2
    Join Date
    Aug 2003
    Posts
    313
    There is no place where you define that symbol. Why not just use Integer.MAX_VALUE for infinity.
    ~evlich

  3. #3
    Join Date
    Aug 2006
    Posts
    3

    Exclamation

    like this?

    UPDATE: FIXED

    PHP Code:
    // make prime number

    class prime  {

      public static 
    void main (String args[]) {

        
    int number1prime;
        
    int lowerupperstep;
        
    int x;
        
    Integer.MAX_VALUE;
        
    lower 0;      // lower limit of table
        
    upper 1;  // upper limit of table
        
    step  1;     // step size


        
    for (number1=lowernumber1 uppernumber1 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. #4
    Join Date
    Aug 2003
    Posts
    313
    Your loop conditional is inverted. You are saying number1 > upper rather than number1 < upper.

    Hope this helps.
    ~evlich

  5. #5
    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. #6
    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.

Similar Threads

  1. Prompt for unknown number of parameters
    By garf in forum VB Classic
    Replies: 0
    Last Post: 02-22-2005, 06:12 AM
  2. Creating a shell for linux in C
    By newbie29 in forum C++
    Replies: 1
    Last Post: 02-21-2005, 03:04 PM
  3. Help
    By George in forum oracle.general
    Replies: 0
    Last Post: 04-01-2003, 12:57 AM
  4. Help
    By George in forum oracle.general
    Replies: 0
    Last Post: 04-01-2003, 12:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center