prime number problem
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
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
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
can you pls show us what code you'v got so far?
java amateur
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
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.
SCJP 1.4 (90%)<br />SCWCD 1.4 (88%)
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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);
}
}
}
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);
}
}
}
SCJP1.4, SCWCD1.4, SCBCD5.0(working on...)
posted 20 years ago
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.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
posted 20 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
SCJP1.4, SCWCD1.4, SCBCD5.0(working on...)
| 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 |











