Campbell Ritchie wrote:Where did it say that buffered readers and tokenizers were quicker? How old was that reference? Have you tested it? How do you know it is accurate?
You need to be circumspect about weird things you find on the net. Here, too, though we usually find errors quite quickly!
Junilu Lacar wrote:
Erandika Gun wrote:I am learning to code through Algorithm contests which requires speed over ease.
So if you win something from advice you get here, will you donate a portion of your winnings to us, to be used towards the upkeep of the site?
Speed over ease, huh... so the idea is to buy now and pay later, too?
Campbell Ritchie wrote:
Do you really mean “learning”?Erandika Gun wrote:. . . I am learning to code through Algorithm contests which requires speed over ease.
Campbell Ritchie wrote:
Why? A tokenizer is legacy code, which you ought not to use in new code. Why are you not using something like Scanner instead, which will find the next int directly.Erandika Gun wrote:. . . I used a BufferedReader and StringTokenizer for this. . . .
Paul Clapham wrote:Perhaps you didn't wait long enough? It could take quite a while to figure out if 600 billion numbers are factors of that number, which is what you would be doing if it were prime.
By the way let me point out that the smallest non-trivial divisor of any number must be prime. You don't need to do that check.