• Post Reply Bookmark Topic Watch Topic
  • New Topic

Prime numbers problem  RSS feed

 
Timothybruce Williams
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am working on a problem. I would like to create 2 methods. One to determine if an integer is a prime number, and 2 to determine how many prime numbers are between 2 integers. This is what I have so far!



Can someone please help?
 
Prasanna Raman
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried running the program? What do you get?

What does your countPrimes() method do currently? Work out on a piece of paper exactly what it should do before you start modifying your code.

Also, kindly use code tags whenever you post code. It looks much better
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Have you got all the {} in the right place? It looks as though you had methods inside other methods.
What you are doing in count primes is counting numbers. You do not appear to be checking whether those numbers are prime or not.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!