Java Letter Distance?

java

Solution

For strings containing a single character:

String s1 = "A";
String s2 = "c";

int result = ((int)s2.toLowerCase().charAt(0) - (int)s1.toLowerCase().charAt(0)) + 1;

If you are working with just characters (no strings), then Java's `Character` class has a static `toLowerCase()` method.

Edit

For the case where the result may be negative ('A' - 'C'):

result = Math.abs(result);

Problem

Is there a way to find the distance of letters in Java? What I mean is for example: ``` A -> C = 3 (as A, B, C) B -> G = 6 (as B, C, D, E, F, G) R -> Z = 9 (as R, S, T, U, V, W, X, Y, Z) ``` (I am looking for distance that is inclusive of the first letter) Thanks!

Original source