class ReturnNumberOfPrimes
{
public static void main (String args [])
{
int c[ ]={12,13,7, 2, 5};
int a=ReturnNumberOfPrimes(c);
System.out.print(a);
}
public static int ReturnNumberOfPrimes (int list [ ])
{
for (int i=0; i%26lt;list.length; i++)
{
if(list[i]%2!=0 %26amp;%26amp; list[i]%3!=0)
}
return i;
}
How do I fix this, so that it prints the number of primes in array? With my program, it should print 4?
don't know about the logic, but right off it looks like your returnnumberofprimes function isn't returning the correct value...you need to return the number of found primes, rather than the counter for your 'for' loop. so you need another variable to count in your 'if' command when a prime is found.
tarot cards
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment