[Solved] Android – How to converting inputted random words to numbers [closed]


I can give you a solution:

/**
     * Convert a given string to array of numbers.
     * 
     * @param words
     *            The string
     * @param startValue
     *            The start value for the array.
     * @return The array of numbers.
     */
    public static final int[] wordsToNumbers(String words, int startValue) {
        if (words == null || words.length() == 0) {
            return new int[0];
        } else {
            int[] numbers = new int[words.length()];
            int value = startValue;
            for (int i = 0; i < words.length(); i++) {
                numbers[i] = value;
                value++;
            }
            return numbers;
        }
    }

Let’s test this:

String test = "STACK";
int[] numbers = wordsToNumbers(test, 1);
for (int i = 0; i < test.length(); i++) {
    char c = test.charAt(i);
    System.out.printf("%s=%d\n", c, numbers[i]);
}

Output:

S=1
T=2
A=3
C=4
K=5

6

solved Android – How to converting inputted random words to numbers [closed]