So for a class, I need to make a program that scores a word based off of scrabble values for a letter. So aa
should be 2
since 1 a
is worth 1 point. But for some reason, my program only shows aa as 1 point.
import java.util.Scanner;
public class Scrabble {
public static void main(String[] args) {
String[] alphabet = {"a", "b", "c", "d", "e",
"f", "g", "h", "i",
"j", "k", "l", "m", "n", "o",
"p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z"};
int[] values = {1, 3, 3, 2, 1, 4,
2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10,
1, 1, 1, 1, 4, 4, 8, 4, 10};
Scanner kboard = new Scanner(System.in);
System.out.println("Input your word.");
String choice = kboard.nextLine();
int score = 0;
for(int i = 0; i < choice.length(); i++) {
for(int n = 0; n < 26; n++) {
if(choice.substring(i).equals(alphabet[n]))
{
score += values[n];
}
}
}
System.out.println("The score for your word is " + score);
}
}