• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

prime number problem

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.....
please help me out
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you pls show us what code you'v got so far?
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.rentacoder.com/RentACoder/default.asp
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Follow a stepwise approach:
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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: 17735
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by lalit upadheyay:
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.
 
lalit upadheyay
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Junilu! i am sorry , i was just trying to help but i hadn't realized till my last reply that the imapct would be bad. Thanks for the advice. I would take care of ur advice in my future postings.
 
Curse your sudden but inevitable betrayal! And this tiny ad too!
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic