Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Logic problem  RSS feed

 
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!!!
 
Java Cowboy
Sheriff
Posts: 16083
88
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.
 
Marshal
Posts: 58395
178
  • 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.
 
lowercase baba
Bartender
Posts: 12613
50
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.
 
Ranch Hand
Posts: 4702
9
Java Scala
  • 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
Marshal
Posts: 58395
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!