CNET中国旗舰网站

ZDNet China | CNET科技资讯网 | 政府采购 | 行业网站联盟





 
标题: [问答] java谁可以帮我看看代码的对错?
CNET开发专家团
专家组
Rank: 10Rank: 10Rank: 10



UID 259939
精华 1
积分 53
帖子 4
威望 -2
ZD币 16 元
阅读权限 255
注册 2007-11-9
状态 离线
  楼主
发表于 2008-4-8 10:51  资料  个人空间  短消息  加为好友 
开发者在线

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 &lt; z.size()-1; i++)
<br>   {
<br>      i+= a.getLettScore();
<br>   }
<br>   return i;
<br>
<br>  //or for(int i = 0; i &lt; z.size()-1; i++)
<br>   //{
<br>   //  i+= z.getLetterScore();
<br>   //  }
<br>   // return i;
<br>}
<br>}



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

顶部
热点频道推荐: C/S开发| 数据库| WEB开发| 嵌入式| 项目管理|
CNET开发专家团
专家组
Rank: 10Rank: 10Rank: 10



UID 259939
精华 1
积分 53
帖子 4
威望 -2
ZD币 16 元
阅读权限 255
注册 2007-11-9
状态 离线
  沙发
发表于 2008-4-8 10:51  资料  个人空间  短消息  加为好友 
------------



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

顶部
热点频道推荐: C/S开发| 数据库| WEB开发| 嵌入式| 项目管理|
 



当前时区 GMT+8, 现在时间是 2009-7-5 04:19

  Powered by Discuz! 5.5.0 © 2001-2007 Comsenz Inc.
Processed in 0.062627 second(s), 4/3 queries

清除 Cookies - 联系我们 - ZDNetChina中文社区 - 无图版