Gets the sum of all char indexes in a word - Java java.lang

Java examples for java.lang:char

Description

Gets the sum of all char indexes in a word

Demo Code


//package com.java2s;

public class Main {
    /**/*from  ww w.  j av a2s  .c  o  m*/
     * Gets the sum of all char indexes in a word
     *
     * @param word Word to get the score for
     * @return The word score
     */
    public static long getWordScore(String word) {
        long sum = 0;
        for (int i = 0; i < word.length(); i++)
            sum += word.charAt(i) - 64;
        return sum;
    }
}

Related Tutorials