File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes alphabet equal to numbers? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "alphabet equal to numbers?" Watch "alphabet equal to numbers?" New topic
Author

alphabet equal to numbers?

Kanika Bansal
Greenhorn

Joined: Nov 01, 2008
Posts: 2
Is there any way in java by which we can associate each number of the alphabet with a number directly? like a=1, b=2 , c=3 and so on.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
Welcome to JavaRanch

You don't need to associate numbers; they are there already. If you go to Unicode, you find there already are numbers. In fact the computer doesn't store 'a'; it stores 0x61 (97 in decimal).
You can use % 0x20 after 'a', or 'a' - 'a' + 1. Both will work, but will give very peculiar results for things which aren't letters. They produce an int result.
Kanika Bansal
Greenhorn

Joined: Nov 01, 2008
Posts: 2
well dats ok but i m not looking for dat. actually i need to do a program in which i have to see dat if a char = a, then it reads d value stored at 0 in an array. similarly if it is b, then from position 1 and so on till z.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11170
    
  16

I have no idea what 'dats', 'm', or 'd' means. Data? monkey? dictation?

We really prefer folks to use real words here. Many of our visitors don't have English as a first language, so using shorthand like this makes understanding complex topics even MORE difficult.

Why do you need the value for 'a' to be in the 0th element in the array? Memory is cheap. Why not have an array with, say, 127 elements, and then just not use most of them? 'a' would refer to element 97, 'b' to 98, etc., with elements 0-96 emtpy.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18546
    
  40

Originally posted by Kanika Bansal:
well [th]ats ok but i [a]m not looking for [th]at. actually i need to do a program in which i have to see [th]at if a char = a, then it reads [the] value stored at 0 in an array. similarly if it is b, then from position 1 and so on till z.


Unicode for the alphabet is linear. So... if you convert the letter to unicode, then subtract the unicode for "a", you will get zero for "a", one for "b", two for "c", etc.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: alphabet equal to numbers?
 
Similar Threads
WA #1.....word association
document.write()
What is your favorite letter?
Validation Using Regular Expression in Javascript
Regular Expression in Javascript