I need to write a program for game \"scrabble\". When I give an input it need to
ID: 3626820 • Letter: I
Question
I need to write a program for game "scrabble".When I give an input it need to run the word through loops to find out the
score for each letters of the word given and sum up the score and display it.
The score for each letters are given and I have put them into the letters[][] array.
Score corresponds to the index number.
ex) space score 0. 'E', 'A', 'I', 'O', 'N', 'R', 'T', 'L', 'S', 'U' score 1, and so on.
import java.util.Scanner;
public class Scrabble {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// scan input word and convert to array
String word = input.next();
char[] arrayFromStr = word.toCharArray();
char[][] letters = { { ' ' },
{ 'E', 'A', 'I', 'O', 'N', 'R', 'T', 'L',
'S', 'U' },
{ 'D', 'G' }, { 'B', 'C', 'M', 'P' },
{ 'F', 'H', 'V', 'W', 'Y' }, { 'K' }, {
'J', 'X' },
{ 'Q', 'Z' } };
int i;
int score = 0;
for (i = 0; i < arrayFromStr.length; i++)
for (int j = 0; j < letters.length; j++) {
if(arrayFromStr == letters[j])
score = j;
int sum = 0;
sum += score;
}
System.out.println(score);
}
}
Explanation / Answer
Hey, you forgot that you had a two array variable for letters. You were trying to compare a character with an array of characters. All i did was add in a for loop really. code is in the link: http://codepad.org/A8pVnUTI PLEASE RATE