0
What do i do wrong.. Pls help me
6 Answers
+ 5
You never wrote the return type of the function check.
Fix:
static boolean check(....
You also never imported the package required for the ArrayUtils method. I believe it is java.lang.Object.
ps: You need to do something with the boolean returned.
Ex/
System.out.println(check(5));
+ 5
Ah, I missed this error. Move int a; to the parameters of the function
static boolean check(int a){
Then remove the "int a;" you wrote.
+ 4
I think you may need to actually download something from apache commons in order to use arrayutil. according to stack over flow it's not part of the javas ordinary library.
Consider making your own contains function
This is called a linear search:
private static boolean contains(int[] array, int key){
for(int i = array.length-1; i >=0; i--){
if(array[i] == key)
return true; // found item
}// end for
return false; // did not find item
}
You can then remove that Object import I tolled you to add (sry).
And re-write contains boolean.
boolean contains = contains(opts, a);
Also your if statements are redundant. You can just write:
return contains;
At the end of the check function, instead of those if/else statements.
0
Thanks for the help but again it is not working
0
Again the problem appears to be something with variable 'a'
0
Ok thanks i will try that on pc