Campbell Ritchie wrote:The Sieve is hardly more complicated, and much more efficient; that code will run in quadratic time and looks inefficient to me.
Bobby Smallman wrote:. . . A simple yet efficient way . . .
I suspect the Sieve is quadratic complexity, too, but still much faster.
Head First Java is the best Book for Java Beginners- Lot of us have used that book and benefited from its style of presentation. Also you can check out the BunkHouse-Beginning Java for other books reviewed by JavaRanch.