• Post Reply Bookmark Topic Watch Topic
  • New Topic

i need help with array  RSS feed

 
milad yalda
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi want to make a method who generates the prim tal you, so you type the number you want and then the program will show all prime numbers from one to the number you gave. This is my code:


I must have it in a method and the method must return the answer to the main method so what is worong with tis method?

Thanks for all help.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What makes you say it's wrong? What are you expecting and what is it you're getting? Please TellTheDetails ( <-- click on the link for some tips on how to ask questions to maximize your chances for getting an answer)
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
milad yalda wrote:I must have it in a method and the method must return the answer to the main method so what is worong with tis method?

Well, first off you seem to be copying the results of a previous calculation, which is probably redundant. There is, however, absolutely nothing wrong with using the results of previous calculations to work out the next prime number (or numbers) in series.

2. Where is the user's original limit? I don't see any sign of it in that code.

3. If you're using the user's limit to create the array size, it's very wasteful. There is a much better estimate: limit / ln(limit), but it needs a bit of correction because it's too small in most cases (there are even better ones too). Best way of all: use an ArrayList rather than an array, because it will grow as needed.

4. All prime numbers greater than 3 have the form 6n±1. How do you think that might help you?

HIH

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!