-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchElementInArray.java
More file actions
35 lines (26 loc) · 936 Bytes
/
SearchElementInArray.java
File metadata and controls
35 lines (26 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package ArrayProgramms;
import java.util.Scanner;
public class SearchElementInArray {
//creating method for search functionality
public String SearchElement(int[] arr,int num){
for(int i=0;i<arr.length;i++){
if(arr[i]==num){
return "Number found at array index "+i;
}
}
return "Number not exist in array";
}
public static void main(String[] args) {
int[] arr={10,52,45,63,78,58,69,45};
// create Scanner object
Scanner sc=new Scanner(System.in);
System.out.println("Enter Number : ");
int num=sc.nextInt();
//create object of class
SearchElementInArray obj=new SearchElementInArray();
//calling method and storing the result
String result=obj.SearchElement(arr,num);
//display the result
System.out.println(result);
}
}