- 2
How to fix the errors in this code?
https://code.sololearn.com/cpL2QbDyqbB7/?ref=app https://code.sololearn.com/cCSidz7eMh9t/?ref=app
8 Respuestas
0
The problem comes from the Median function: you don't pass the array to it and it is not a method of the class – "this" referrs to nothing and "a" cannot be accessed either.
Either make Median a method of the class and change "this" or pass the array as a parameter
0
Can you pls show me how to do it I really need it , it is for school purpose Lisa
0
Did you change the code?
I cannot find the Median function in it...
0
Yes because I try a another method but the output is incorrect but there is no error how to fix it though pls help Lisa
0
There are several things:
* sort the array before searching the median – use the method that the class already has!
* according to the task description, the median should be a method not a function
Here's the basic median method based on you attempt in the main. Put it into your class
public double Median() {
this.insertionSort();
long mdn;
if(nElems%2 == 1){
mdn=a[(nElems+1)/2-1];
}
else {
mdn=(a[nElems/2 - 1]+a[nElems/2])/2;
}
return mdn;
}
0
Sololearn has a Java course. Why don't you give it a try? OOP will be explained in it.
0
Okay I will try thanks anyways Lisa
0
Sometimes I just don't get what is the error in my program so is there anything with which my program is corrected on it's own and I can see the changes for better understanding