Very Heavily Edited. I think either you want this:
class CharStorage {
/** set offset to 1 if you want b=1, o=2, y=3 instead of b=0... */
private final int offset=0;
private int array[]=new int[26];
/** Call this with up to 26 characters to initialize the array. For
* instance, if you pass "boy" it will init to b=0,o=1,y=2.
*/
void init(String s) {
for(int i=0;i<s.length;i++)
store(s.charAt(i)-'a' + offset,i);
}
void store(char ch, int value) {
if(ch < 'a' || ch > 'z') throw new IllegalArgumentException();
array[ch-'a']=value;
}
int get(char ch) {
if(ch < 'a' || ch > 'z') throw new IllegalArgumentException();
return array[ch-'a'];
}
}
(Note that you may have to adjust the init method if you want to use 1-26 instead of 0-25)
or you want this:
int getLetterPossitionInAlphabet(char c) {
return c - 'a' + 1
}
The second is if you always want a=1, z=26. The first will let you put in a string like "qwerty" and assign q=0, w=1, e=2, r=3...