This week's giveaway is in the Java/Jakarta EE forum.We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!See welcome thread
Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# prime number problem

Greenhorn
Posts: 12
hi friends,
i will be grateful if any one can send me a program that generates a prime number upto 500 and i need to pick up a single prime number from it...

It is a bit urgent and i need it by today evening.....

Ranch Hand
Posts: 1281
can you pls show us what code you'v got so far?

Ranch Hand
Posts: 4632

Ranch Hand
Posts: 121
1> first decide the logic u want to use to detect if a number is prime or not
2> write a for loop for 0 to 500 and check if each number is prime or not

3> Start coding with whatever you know

4> Now post your doubts here. You will surely get a good response.

Ranch Hand
Posts: 110
Hi sreedhara satuluri

You asked an easy logical question. The simple straight answer is --

class PrimeGenerator500
{
public static void main(String []args)
{
for(int i=2;i<=500;i++)
{
boolean flag=true;
for(int j=2,k;j<=i/2;j++)
{
if(i>2)
{k=i%j;
if(k==0)
{
flag=false;
break;
}
}
}
if(flag)
System.out.println(i);
}
}
}

Sheriff
Posts: 11648
187

Hi sreedhara satuluri
You asked an easy logical question. The simple straight answer is --

Lalit,

Around here, the previous replies to the original post (OP) are customary for solicitations for solutions to homework/school assignments. We prefer to help folks learn to do things themselves and perhaps learn something in the process. We believe that giving out solutions the way you just did is counter-productive and detrimental to the OP.