Carey Brown wrote:On line 8 you are decrementing nbrAuthors. Why? How about
Line 11, if nbrAuthors is a quanity then this loop will go one too far.
Test for duplicate on lines 14-17 is ok, however for each author that is not a duplicate line 20 would be executed. This will overwrite authors[nbrAuthors] over and over. You shouldn't be doing this write inside the loop. Instead, setup a boolean variable, e.g. "isDuplicate", before the loop and inside your duplicate detection set this to true. Then only after the loop completes use this variable to decide whether or not to add the new author. Only if you actually add it do you want to increment nbrAuthors.
Functionally equivalent. Follows more normal Java convention.Jordi Sedo wrote:Done, it's for a technical reason or more like a good practise?
All things are lawful, but not all things are profitable.
Knute Snortum wrote:Also, it's easier to make a mistake when writing if(isDuplicated!=true). And it's advisable that if you can write something in code that's shorter (as long as you aren't obfuscating the meaning) it's better.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |