2017-05-27 56 views
-5

我很困惑,返回语句应该是什么。private static int [] wordLengths(String [] words)

这是我有:

private static int[] wordLengths(String[] words) 
{ 
    String[] words = in.nextLine(); 
    String[] array = 0; 

    if(words > 0) 
    { 
     int[] wordLengths = words.length(); 
    } 
    return 
} 
+0

只是word.Length – MarBVI

+0

你知道这个程序是不正确的。试着多解释一下你想要做的事情,以便人们可以帮助你。 – VK321

+1

我认为我们其他人也很困惑。什么'return'语句应该取决于你的例程应该做什么。你能告诉我们吗? –

回答

0

上面有太多的问题代码:

你需要得到字长=>则返回一个int INT []

你方法帕拉姆有:String[] words那么你不能在方法体内再次打磨它

words是一个数组不能用来比较if(words > 0)

当你的方法名,你只需要简单的代码:如果你需要一个字符串的长度

public static int wordLengths(String[] words) 
{ 
    return words.length; 
} 
+0

她的方法名称是'wordLengths',并且您的代码只返回一个长度。我猜测答案并不那么简单。 – ajb

0
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; 
} 
相关问题