私は現在Javaプログラミングのクラスに入っており、Javaを完全に新しくしています。私はこれは私が得たコンパイラエラーで値を45.3プリミティブ型を使用したバイナリ検索
class findValue {
public static void main(String args[]) {
double a[] = new double[6]; //declaration
a[0] = -3; //initialization
a[1] = 10;
a[2] = 5;
a[3] = 24;
a[4] = 45.3;
a[5] = 10.5;
int n = a.length; //storing length of array
int temp = 0; //declaring temporary storage place
for (int i = 0; i < n; i++) {
for (int j = 1; j < (n - i); j++) {
if (a[j - 1] > a[j]) {
temp = (int)a[j - 1];
a[j - 1] = a[j];
a[j] = temp; //bubble sorting
};
};
};
System.out.println("45.3 found" + binarySearch(a, 45.3));
};
public static void binarySearch(Integer[] a, int x) {
int low = 0;
int high = a.length - 1;
int mid; //values for binary search
while (low <= high) {
mid = (low + high)/2; //setting value for searching
if (a[mid].compareTo(x) < 0) {
low = mid + 1;
}
else if (a[mid].compareTo(x) > 0) {
high = mid - 1;
};
};
};
をバイナリ検索を使用するプログラムを作成しようとしています:
Line: 25
method binarySearch in class findValue cannot be applied to given types;
required: java.lang.Integer[],int
found: double[],double
reason: actual argument double[] cannot be converted to java.lang.Integer[] by method invocation conversion
は、エラーメッセージについて何を理解していませんか? –
プリミティブ型は私のために少しファジィです。彼が一番私を得ているのは変換エラーです。 –
あなたは二重配列を渡しており、メソッドは整数配列を期待しています。 – RamPrakash