• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Logic problem

 
Tarun Oohri
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone
I am not able to understand this program, It counts the repeated characters in the given string.
Can you tell me how it is doing so, what is the logic behind this.
What 65,91,97,123 denotes here ?
Thanks in advance!!!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those numbers are character codes (ASCII). It only counts characters in the range 65 to 91 and 97 to 123 (inclusive), which are letters A to Z and a to z, and the characters [ and {. The fact that it includes [ and { is probably a bug. It should have been < 91 and < 123.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you find that code? It would have been far better to use a method like this than those error‑prone <= operators.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12100
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
those are what's called "magic numbers", because you have to have some magic to know what they mean. They should be avoided at all cost.
 
Randall Twede
Ranch Hand
Posts: 4371
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
awesome Campbell! thanks for sharing that for when i might need it!
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic