【发布时间】:2014-11-28 12:41:26
【问题描述】:
public static int get(String A) // it is a method
{
int count = 1;
for (int i = 0; i < A.length(); i++) // So A reads line (any word, for example "Car"), so I understand that length will be 3 and that java will check all the characters.
{
int num = (A.charAt(i) - 'A') + 1;
count *= num;
}
return count;
}
【问题讨论】:
-
因为
String#charAt()是一个方法,而不是一个数组实例。你写“A”来表示类型char,而不是“A”,它是String。 -
@barakmanos 如果拼写困扰您,只需编辑它。然后将其余显然是答案的评论放在答案部分。
-
@weston:这并没有真正困扰我,我只是认为如果我发表评论而不是编辑,OP 会注意到它。至于回答它,这里已经有大约 10 个答案(如预期的那样)。谢谢。