This is where Google becomes your best friend. I would suggest searching for examples on the web. I'm sure that someone has done this before.

EDIT: I know it's Java, but the languages are very similar. Try searching at http://forum.java.sun.com/index.jspa. I searched on "prime number" and it returned plenty of results. Perhaps one will be able to help you.