Here's the question: Do more baby names start with A or B? Write code to count and print those two counts (A count, then B count).I then write this code down:table = new SimpleTable(baby-2010.csv);count1 = 0;count2 = 0;for (row: table) {// your code hereif (row.getField(name).startsWith(A)) {count1 = count1 + 1; }if (row.getField(name).startsWith(B)) {count2 = count2 + 2; }}print(A count:,count1)print(B count:,count2)I ran the code which then came out like this: A count: 258 B count: 198 Any ideas as to why this might be wrong?
What's wrong with this
counting
First off, I don't think this is the appropriate place for this question.Second; why are you incrementing count2 by 2 each time you find a name field that begins with a B? Surely this should be incremented by 1, like count 1 is.Out of interest, do you know what the correct results should be?Could you post them?