How to convert a string to alphabets and add [closed]

String str = "ABcDe";
str = str.toUpperCase();//just to be sure you have only capital letters in your string

int sum=0;
for(int i=0;i<str.length();i++){//cycle until the string ends
    sum = sum + str.charAt(i)-64;//'A' in ascii is 65, so 65-'A' = 65-64=1, etc
}

Leave a Comment