This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Logic problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Logic problem" Watch "Logic problem" New topic
Author

Logic problem

Tarun Oohri
Ranch Hand

Joined: Feb 20, 2013
Posts: 175
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

Joined: Aug 16, 2005
Posts: 14116
    
  16

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
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

Joined: Oct 02, 2003
Posts: 11256
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

awesome Campbell! thanks for sharing that for when i might need it!


SCJP
Visit my download page
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
You're welcome
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Logic problem