Hello. My program is supposed to accept #test cases. For each test case, it must accept two integers as a range, then return all prime numbers within the range.
Currently, it prints odd numbers within the range.
So I suspect my problem is within the Boolean i'm using to test whether a number is prime or not.
I pulled the code for the Boolean from this site - http://www.mkyong.com/java/how-to-determine-a-prime-number-in-java/ Maybe I didn't quite understand it, or maybe that's not my real issue.
Any help would be greatly appreciated. Please, and thank you!
albert abbene wrote:Any help would be greatly appreciated. Please, and thank you!
Another little wrinkle for you: Your program accepts ints for its range values, and yet uses a calculation method that takes a long. There's nothing intrinsically wrong with it, but it will slow things down unnecessarily, because arithmetic on longs takes longer (no pun intended). It also wastes space, because your ArrayList has to hold Longs when it could be holding Integers.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
I can see a serious problem in that code.
Also, why are you checking individual numbers for prime‑ness at all? There is a far better way to create a large range of prime numbers.
I think the link you provided isn't very good. There isn't enough explanation of what the different examples do, there are too many similar examples without enough information to distinguish them from one another, and there is another problem in the code shown there which you have fortunately not committed here.
You are HERE! The other map is obviously wrong. Better confirm with this tiny ad: