Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Character comparison  RSS feed

 
Thanraj Danz
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can a character be compared from A-Z or a-z??



How does this code work ? What is the logic behind this ??
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that a char is not a letter but a number. When you are writing c it is not really '&' or 'x'. It is 38 or 120. You can read the value (in hexadecimal) here. So what you are doing is testing whether your number c is greater or equal to 65, etc.
 
Thanraj Danz
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell and added if i increment the char will it point out to the next alphabet in the list ???
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanraj Danz wrote:Thanks Campbell and added if i increment the char will it point out to the next alphabet in the list ???

Why don't you write a small program to find it out? (Experimenting is a great way to learn things).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!