私は "一般的な配列を持つことはできません。私のクラスメートの誰もそれを理解することができず、どちらも私たちのクラスのTAを持っていません。これは可能なのですか?もしそうなら、正しい方向に私を向けることができますか?あなたは Javaで一般的な配列を作成しませできおかげ一般的な線形検索
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
String type = scan.next();
int length = scan.nextInt();
//checks the type and makes the appropriate array
if (type.equals("I")) {
int[] anArray = new int[length];
for (int i = 0; i<length; i++) {
anArray[i] = scan.nextInt();
}
int key = scan.nextInt();
linearSearch(anArray, key); //Error, the method is not applicable for the arguments
}
}
public static <E extends Comparable<E>> int linearSearch(E[] list, E key) {
for (int i = 0; i<list.length; i++) {
if (list[i].equals(key)) {
return i;
}
}
return 0;
}