Array Question 3

Home / Java Practice Question / Array Question 3

Array Question 3


Question 3. Write a Program to search a number in array.

Program-


class Solution {

    public int search(int arr[], int n, int k) {

        for(int i=0;i<n;i++){

            if(k==arr[i]){

                return i+1;

            }

        }

        return -1;

    }

}