Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

(Java) Method to check for primeness

Name: Anonymous 2006-11-06 21:52

So let's suppose I have an array of 100 integers.

I want to take each integer in the array (primes[i]) and send it to a boolean method. The method is supposed to take the integer and see if it's prime or not and return true or false to main. In main, I'm supposed to display the prime integers and also show the entire array via println. Here's what I have, how do I fix?

public static void main(String[] args)
    {
     int[] primes = new int[100];
     for(int i=0; i<primes.length; i++)
     {
      double k=(1+Math.random()*100);
      primes[i]=(int)k;
      System.out.println(primes[i]);
      isprime(primes[i]);
     }
    }
public static boolean isprime(int x)
    {                     
        for (int test = 2; test <= x; test++) 
        {
            if (x % test == 0)
            {
             
            }
        }   
    }
}

Name: Anonymous 2006-11-07 6:44

>>1
Use Python lol
No need for arrays
Check n to divide from 2 to floor(sqrt(n))
More information here: http://python.org

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List