Ranter
Join devRant
Do all the things like
++ or  rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Comments

Niddam3153yIt could be 'count' that messes stuff up. Have you tried using 'o < i / 2' and adding primes at the end of your array instead?

vrpg19985983y@Niddam honestly I was bored and wanted to save all those prime numbers in a .txt just in case (no one knows when you will need a prime number~) but my code took 1hr to finish this and I just moved to other things. Also, I changed the code a little since I posted this: saved 1, 2 and 3 since the beginning and start comparing only even numbers and other rule that I don't really understand but that I found in an old math book. Now it runs way faster than it did originally. And, in case you are wondering: 9999991 is the biggest prime number within 1 and 10M and there are 664580 prime numbers.

curlyDev5003y@vrpg1998 i dont know what you need them for? But, making it json/xml and upload them to github will be perfect(i would do it for you) so others don't reinvent the wheel?

vrpg19985983y@curlyDev life is like prime numbers, no one knows what will happen.
¯\_(ツ)_/¯ (maybe for something that needs random numbers that file will help...) 
Well this code is wrong in so many levels ;)
You can run from 2to(I/2) in the inner loop and you can use mod instead of an array
There are more hacks, such as checking if the number is odd and acting accordingly 
For anyone actually interested:
1st tge running time on this is horrible. It's n^2 and can be reduced to n root n at best (and I'm not even talking about implementation). If you want to do thus later on, google prime number seive. For context my seive takes less than a second to generate all primes less than 10M, instead of the ten hours it would take you.
2nd, never print out a number you're computing unless it's for debugging. IO takes longer than CPU tasks and can end up slowing your progress by a lot.
3rd, there's a site online be with "prime facts". I use it often whrn I want to find a 300 digit prime for example. Just Google "the prime pages" 
vrpg19985983yThanks for your comments! This is what help people to grew professionally and with all I've read here I learned things I didn't know. I really appreciate that you took your time to help me. :)

I wrote a thing like this once. Never felt like optimising it, but got it from not finishing after a day and a half, to finishing the first billion or so prime numbers in minutes. I will try to dig it up if you want.

itzyzex14933yWHAT KIND OF HUMAN ARE YOU!!!! YOU ARE USE ECLIPSE IS ONE THING BUT THE FREAKING WHITE THEME DAMN
Related Rants
I think I've made a mistake...
(Sorry for the quality tho)
undefined
eclipse
java
prime numbers