How to search an element in an array in java

0

 


In this blog we will how to search an element in an array. 

We are given an array and a number num we have to find out whether the number is present in the array or not.


import java.util.Scanner;
class HindiCodingCommunity
{
public static boolean search(int []arr , int val)
{
for(int i:arr)
{
if(i==val)
return true;
}
return false;

}
public static void main(String args[]){
int arr[]={45,85,25,61,13,29,43,72,55,39};
System.out.println(search(arr,49));
}
}

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !