I have an array of numbers 1 to 10 and I am taking a number from user.
Now I want to check whether that number is present in my array or not so is there any way to search it. I wanted it to be searched using loop as we to do in C programming
I have an array of numbers 1 to 10 and I am taking a number from user.
Now I want to check whether that number is present in my array or not so is there any way to search it. I wanted it to be searched using loop as we to do in C programming
Suppose the following is the scenario
int numbers[] = { 1, 2,3,4,5,6,7,8,9,10 };
//easiest way if your array is already sorted is to use binarySearch
if(Arrays.binarySearch(numbers, number_input_by_user) >=0 ){
//found in array
}else{
//not found in array
}
If your array is not sorted you can use
Arrays.sort(numbers);