Harish Shivaraj wrote:Remove your print statement from inside the loop to outside.
Paul Clements wrote:
Saw this idea a few weeks ago and it stuck with me. Seems a really clever way to count occurrences of A-Z in a string, with a minimum of fuss.
To explain. We are taking advantage of the fact that A-Z in char is 65-90. Therefore by subtracting 65 from the current char you end up with a number between 0-25. This provides you with an array index to store the count for that particular char. To display you just add 65 to the current array index and display the integer held in that slot.
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
(...)
i know the 1 times, 2 times its a result of the loop. as it is counting the number of times a is present. the loop goes trhoug finds an a, outputs the println statement,
the loop goes around again finds another a, outputs the println statement. If i could get the println statement outside of the for loop i would avoid this result, but if i do then the variables inside of the loop block are out of scope and cat call them.
Any suggestions?
There are three kinds of actuaries: those who can count, and those who can't.
My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards.
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
|