System.out.println("Enter a sentence to get it translated into Pig Latin: ");
String sentence=kb.nextLine();
String[] words = sentence.split(" ");
char a=words.charAt(0);
问问题
851 次
2 回答
1
发生的是这words
是一个数组,并且charAt()
为String
s 定义了方法。所以你想使用:
words[index].charAt(0)
相反, a在数组中index
的位置在哪里。String
于 2014-02-02T21:05:29.473 回答
0
words 是一个字符串数组。尝试使用单词[索引]。拆分后,子字符串将存储如下 -
Enter = words[0]
a = words[1]
sentence = words[2]
to = words[3]
get = words[4]
it = words[5]
translated = words[6]
into = words[7]
Pig = words[8]
Latin: = words[9]
访问 words[index].chartAt(0) 将返回相应子字符串的第一个字符。
于 2014-02-02T21:06:04.187 回答