【发布时间】:2014-06-06 01:53:23
【问题描述】:
我的老师布置了一个问题,这里是:
编写一个将单词输入数组的程序。当一个单词输入两次时,程序将停止。使用以下方法:
static boolean findWord(String s, String[] arr)
// return true if s is found in arr, false otherwise
输入完成后,你的程序会按排序顺序输出列表。
我对函数的这个参数有点迷茫
String[] arr
它正在搜索什么类型的参数输入。到目前为止,这是我的代码。
public static void main (String[] args) {
c = new Console ();
String words[] = new String[50000];
for(int i=0;i>-1;i++) {
c.print("Input word: ");
words[i]=c.readLine();
findWord("apples",What goes here?);
}
}
static boolean findWord(String s,String[] words) {
return false;
}
任何时候我尝试在现场放入某种数组或值,例如
findWord("Hello",words[0])
或者我得到以下错误:
No applicable overload method named "findWord" was found in type E3_Q5. Perhaps you wanted the overloaded version "boolean findWord(java.lang.String s,java.lang.String[] words);" instead?
这是什么意思?他想让我放什么?
【问题讨论】:
-
words[0]是做什么的?您的方法期望作为第二个参数是什么? -
我不知道。问我的老师。同样 words[0] 访问 words 数组的 0 索引。
-
findWord应该做什么?它需要什么来完成它的工作? -
我假设,它需要当前单词和数组位置,如果在数组中找到该单词,则返回 true 或 false
-
如果您不理解您的作业,您需要向您的老师寻求说明。您的方法被声明为
static boolean findWord(String s,String[] words) {。第二个参数的类型为String[]。你在findWord("Hello",words[0])中作为第二个参数传递了什么?word[0]是什么? `
标签: java function parameters