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)
{
}
}
}
}
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)
{
}
}
}
}