Nonsense. It's an int. that is about the one bit that is correct. A double can introduce imprecision, and cause the loop to malfunction.rudradutt joshi wrote: . . . for correct results you should use double as holder of length.
i.e.
Campbell Ritchie wrote:
I am not sure I understand the bit about a List. How would a List help with counting?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie wrote:
Nonsense. It's an int. that is about the one bit that is correct. A double can introduce imprecision, and cause the loop to malfunction.rudradutt joshi wrote: . . . for correct results you should use double as holder of length.
i.e.
to double is increase precision.((Integer) letterCount.elementAt(ch)) / textLength)
Please explain why that won't work. And it is unnecessarily complicated.Rudradutt Joshi wrote: . . . I had just provided a work around for calculating correct percentage to enable below code in correct manner.
. . .
Rudradutt Joshi wrote:I guess you will not encounter with the problem Fred mentioned with the above notion, where the dataMap is reiterated once after string parsing completes, so its one time operation in the end.
And you can do all the beautification for displaying data by enhancing toString for the wrapper object, and to further by a method to print map object the way you like.
Campbell Ritchie wrote:
Please explain why that won't work. And it is unnecessarily complicated.Rudradutt Joshi wrote: . . . I had just provided a work around for calculating correct percentage to enable below code in correct manner.
. . .
I preferred Michael Duff's solution. I have a solution of my own, where I multiplied the count by 100 and 1000 and divided twice to get % and 0.1% values. Do you really want the length of the string as the denominator of the division?
returns integer. And will result in 0 in general cases.(((Integer) letterCount.elementAt(ch)) / textLength)
No, you aren't missing anything. But you need to think through the entire process. What number will be calculated and displayed?Rudradutt Joshi wrote: . . . returns integer. And will result in 0 in general cases. . . .