java谁可以帮我看看代码的对错?
谁可以帮我看看这代码哪里有错误?
<br>题目是需要一个单词的得分程序,26个字母有个自己的不同的分数,当user出入一个单词的时候,程序就会计算出这个单词的得分。(下面这个程序代码是嵌套在另一个代码里面的。)
<br>
<br>public class ScrabbleTools
<br>{
<br> /*
<br> * Method: getWordScore - MILD version
<br> * Purpose: Identifies the number of points for a given word
<br> * Parameters: A char[] - an array of characters containing the letters
<br> * of the word
<br> * Returns: an int - the points for the word
<br> * Device I/O: None
<br> * HINTS: This method is called by the main method in the
<br> * ScrabbleScoring class.
<br> * An array of characters (char[]) is just like any other
<br> * array. You can access each element using an index and
<br> * you can process the elements (letters) one-by-one in a
<br> * loop.
<br> */
<br> public static int getWordScore(char[] word);
<br> {
<br>
<br>
<br>{
<br> int i = 0;
<br> a = a.toUpperCase();
<br> if(a == A || a == E || a == I || a == L || a == N || a == O || a == R || a == S || a == T || a == U);
<br> {
<br> i = i + 1;
<br> return i;
<br> }
<br>
<br> else (a == D || a == G );
<br> {
<br> i = i + 2;
<br> return i;
<br> }
<br>
<br> else (a == B || a == C || a == M || a == P);
<br> {
<br> i = i + 3;
<br> return i;
<br> }
<br> else (a == F || a == H || a == V || a == W || a == y);
<br> {
<br> i = i + 4;
<br> return i;
<br> }
<br> else (a == K);
<br> {
<br> i = i + 5;
<br> return i;
<br> }
<br> else (a == J || a == X);
<br> {
<br> i = i + 8;
<br> return i;
<br> }
<br> else (a == Q || a == Z);
<br> {
<br> i = i + 10;
<br> return i;
<br> }
<br> }
<br>}
<br>
<br>
<br> /*
<br> * Method: getLetterScore
<br> * Purpose: Identifies the number of points for a given letter
<br> * Parameters: A char - the letter
<br> * Returns: an int - the points for the letter:
<br> * As shown in the project description for letters
<br> * A through Z, zero for any other character.
<br> * Device I/O: None
<br> * HINTS: This method should be called by the getWordScore method.
<br> * A variable of type char stores a character as a UNICODE
<br> * value which is just a positive integer. You can perform
<br> * integer arithmetic like letter - A which results in a
<br> * number between 0 and 25 for uppercase letters, or you
<br> * can use a char value in a switch expression.
<br> */
<br> private static int getLetterScore(char[] letter)
<br> {
<br>
<br>
<br>{
<br> int i = 0;
<br> for(Character a : z) //or for(int i = 0; i < z.size()-1; i++)
<br> {
<br> i+= a.getLettScore();
<br> }
<br> return i;
<br>
<br> //or for(int i = 0; i < z.size()-1; i++)
<br> //{
<br> // i+= z.getLetterScore();
<br> // }
<br> // return i;
<br>}
<br>}

- 这是一篇来自百度知道的问题
|