# How to Determine prime number and making shape using loop?

• 02-20-2010, 06:35 AM
cyzash
How to Determine prime number and making shape using loop?
Hi!:D
I hav 2 question:

1.How to determine all the prime numbers from 0 until the positive integer given by user?

2. How to display this shape using java?

*
***
*****
*******
*********
***
***
*********
..:cool::confused:
• 02-20-2010, 06:47 AM
Fubarable
Quote:

I hav 2 question:

1.How to determine all the prime numbers from 0 until the positive integer given by user?

2. How to display this shape using java?

*
***
*****
*******
*********
***
***
*********
and...

3. How to ask a question here that shows you've put even a minimal amount of effort towards first trying to answer it yourself.

Please understand that no one is going to do your homework for you, but we'll more than gladly try to help you with your work, providing of course that you first show us this work.

Much luck!
• 02-20-2010, 06:59 AM
cyzash
Sorry, I'm not asking people to do my homework-i'm currently doing it.
• 02-20-2010, 07:14 AM
collin389
then if you are having trouble with a specific part, feel free to ask for help.
• 02-20-2010, 07:23 AM
cyzash
ok...thanx..i don't realize dat it's wrong just to put the question only..
• 02-20-2010, 07:31 AM
collin389
It's not wrong to only put a question, but people here want to help you learn java, not do homework for you. we usually feel that by answering broad questions like "how to make a program that does ..." is doing homework for the asker, and does not teach them anything. We are more inclined to answer questions that have to do with specific problems in your java program like, "I'm getting an error that says '...', here is my code, what am I doing wrong."
• 02-20-2010, 07:40 AM
cyzash
i see...sorry again if i made people to misunderstand the post.honestly no intention to ask people doing myhomework- :(
• 02-20-2010, 07:43 AM
Fubarable
Quote:

Originally Posted by collin389
It's not wrong to only put a question,...

For this type of question, the classic "homework dump", I think that it is wrong since the poster isn't really asking a question at all but rather posting a restatement of the entire homework task itself without showing a bit of work.

Quote:

...but people here want to help you learn java, not do homework for you. we usually feel that by answering broad questions like "how to make a program that does ..." is doing homework for the asker, and does not teach them anything. We are more inclined to answer questions that have to do with specific problems in your java program like, "I'm getting an error that says '...', here is my code, what am I doing wrong."
This I fully agree with.
• 02-20-2010, 07:43 AM
Fubarable
Quote:

Originally Posted by cyzash
i see...sorry again if i made people to misunderstand the post.honestly no intention to ask people doing myhomework- :(

No problem as you're learning both programming and forum etiquette at the same time. Both will get much better with time, I'm sure.
• 02-20-2010, 09:01 AM
cyzash
//hi this my code for checking n printing prime num
//but still can't run
//anybody know why?
Code:

```public void checkNum(int inpNum){  int isPrime=inpNum;  int counter=0;  for(int z=0;z<=isPrime;z++){     for(int y=1;y<=isPrime;y++){  if(z%y==0) {     counter=counter+1;       prime[j]=z;       j++;  }    }if (counter==2) System.out.println(prime[j] +" ");}   }```
• 02-20-2010, 09:25 PM
collin389
Well, you never initialize j
Also, your brute force method is OK I guess but there are much better ways like. Read this: Primality test - Wikipedia, the free encyclopedia
It explains that you only need to check from m to sqrt(n) not n-1, also things like skipping the evens and things like that.