Is anyone there?

  • 6
  • Locked
Implement the main(String[]) method, which displays true if the element is contained in the passed array, otherwise false. The array variable should not change the position of its elements. To search for an element in an array, you need a binary search. To do this, use the static Arrays.binarySearc
You can't complete this task, because you're not signed in.
Comments (9)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Maksim Krasnov
Level 34 , Kyiv, Ukraine
16 June, 16:14
Hello, I received this message. The task failed to pass testing! In the main(String[]) method, use a call to the Arrays.binarySearch(int[], int) method. where is the mistake?
Roman
Level 41
20 June, 09:50
Please post your question with the attached solution in the section Help.
Ace Phelps
Level 9 , United States of America, United States
1 May, 01:59
Arrays.sort(array); Arrays.binarySearch(array,element); if( Arrays.binarySearch(array,element)==array[Arrays.binarySearch(array,element)]-1){ System.out.println("true"); }else{ System.out.println("false"); }
Ace Phelps
Level 9 , United States of America, United States
1 May, 02:01
what am I doing wrong in here , any suggestion ?
Roman
Level 41
4 May, 06:04
Please post your question with the attached solution in the section Help.
Le Phan
Level 14 , Véry, France
26 December 2021, 12:26
/* Is anyone there? */ I had 2 variants of the result after the first attemp failed. In the first variant, I copied the given array to a new array, sort the new one, use the binary search on it, and the verification failed! I was thought, what the hell as every requirement is satisfied?! The error is that: need to use a call of Arrays.binarySearch(int[], int). But I already used that!!! So I gave that a second attemp. Also copy the given array to a new one. This time, I sort and binary search for the given array. After displaying the result, I had returned the given array to its original values. And ... still verification failed against with the same message!!! WTF! Well, I tried to download the solution and "things are the same as my code as my first variant." Err 🤬 The assignment is not hard, but the verification must have something not smoothly run.
John Squirrels Website Admin at CodeGym
27 December 2021, 09:37
Please send us your code.
John Squirrels Website Admin at CodeGym
30 December 2021, 10:14
We have forwarded this issue to our team.
Luka Gedenidze
Level 10 , Georgia
23 April, 20:34
it is not fixed :) thats my code public class Solution { public static int[] array = {9, 8, 7, 6, 5, 4, 3, 2, 1}; public static int element = 5; public static void main(String[] args) { //write your code here int [] array2=Arrays.copyOfRange(array,0,array.length); Arrays.sort(array2); int number=Arrays.binarySearch(array2,element); System.out.println(number>=0); } }