Results 1 to 2 of 2

Thread: Who Knows Java? lol

                  
   
  1. #1
    DCEmu Newbie
    Join Date
    Feb 2006
    Posts
    1
    Rep Power
    0

    Default Who Knows Java? lol

    Hey guys I need Java help lol. I would REALLY REALLY appreicate some help, yes im a desperate sad man for all purposes.... Basically I need a relatively simplep rogram that finds the first 100 prime numbers. I would appreciate any help i could get especailly in regards to the algorithm for finding the primes. I mean like Java is similar to C++ Im just having some difficulty with an algorithm to determine prime numbers. Thanks, any and all help would be appreciated. Thanks, Xavya

    PS ALso i would love you for all eternity thanks

  2. #2

    Default

    Here's my prime number PHP function I wrote a while ago. I don't know Java but it looks like the syntax is almost exactly the same.

    PHP Code:
    function prime($min$max) {
        if (
    $min == 0) { $min++; }
        if (
    $max == 0) { $max--; }
        for (
    $x $min$x <= $max$x += 2) {
            
    $n $x;
            
    $lim $x;
            while (
    $lim $n) {
                if (
    $x $n == 0) { $blah 1; }            
                
    $lim $x $n;             
                
    $n += 2;
            }
            if (
    $blah == 0) { $prime_numbers .= "$x "; }
        }
        return 
    $prime_numbers;

    For the first hundred you'd do this:

    $numbers = prime(1, 100)

    But instead of .= for string concatenation you'd use + and there might be some other things to change around.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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