我对返回语句应该是什么感到困惑。
这是我所拥有的:
private static int[] wordLengths(String[] words)
{
String[] words = in.nextLine();
String[] array = 0;
if(words > 0)
{
int[] wordLengths = words.length();
}
return
}
上面的代码有太多问题:
你需要得到单词长度 =>然后返回一个 int 而不是 int[]
您的方法参数具有:String[] words
,那么您不能在方法主体中再次使用它
words
数组不能用来比较if(words > 0)
作为方法名称,您只需要简单的代码:
public static int wordLengths(String[] words)
{
return words.length;
}
private static int[] wordLengths(String[] words)
{
int[] wordLengths = new int[words.length];
for(int i=0;i<words.length;i++){
wordLengths[i]=words[i].length();
}
return wordLengths;
}