Well, getting into programming Java and I need some information which I thought would be located in my nifty Java source book. But it isn’t.
I took it upon myself, as a test of speed and memory, to find all the prime numbers between 0 and some number one passes along as a command line argument.
I was getting OutOfMemoryExceptions, so I then wrote a quick test program to find out the largest array I could make.
Now, the array I chose was a boolean array because I figured it would be the one which used the least amount of memory, though I suspect it is the same as byte. I would LOVE bit!
At any rate, my program is now bound by a ceiling of 50 million (which it find all primes in in 54 seconds, so long as it doesn’t display progress, which I’ve commented out now that the thing works). Though 50 million is a fine ceiling for finding primes, something around 650 thousand of them, I’m not satisfied. (and the ceiling is 50 Million exactly, 50000001 is the magic error number)
So, the plan is going to be to be able to pass a long integer to it as a ceiling. Not going to bother with double until I get long to work. At any rate, I am about to make an array of arrays (or just multiple arrays) by dividing the ceiling by 50 million to see just how many arrays I need (ceil/50mil + 1 arrays). Already I was wondering… how many arrays of arrays can I have? Or better yet, how many arrays can I have period (whichever is greater)? I can’t seem to find any limits on this, and setting programs up to create huge arrays, destroy them, then create huge arrays +1 takes a looooong time. If I have to I’ll do it, but if anyone can help here I’d appreciate it.
Anyone interested in the algorithm, which is pretty fast as it does no division on any numbers, is welcome to ask. I could email the code or post it.
Oh my, second question to this. In “for” loops I couldn’t find limits on the conditional statement, italicized here:
for (int i = 0; i < ceiling; i++) {
//code
}
Could I put a double in there? I’ve put “ceiling” numbers in the loop which are larger than type int and received no compiler errors, but I’ve never actually tried using anything but an int for these loops. I know the “i++” can’t be any other statement… at least, I tried “i + 2” and it wouldn’t compile…
Wow, long GQ. Maybe I should summarazie:
[li]Anyone know how many arrays I can make in one method? Note: not a main method, if that matters.[/li][li]Do for loops need int types? (this one is just laziness on my part, so feel free to not answer)[/li]
In closing, I suppose with more intensive code I could get by with only making one array at a time, but I am pretty shakey on extensively nested loops and would happily avoid it if I could.
Thanks for help.