-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinearsearch.java
More file actions
45 lines (30 loc) · 1.05 KB
/
linearsearch.java
File metadata and controls
45 lines (30 loc) · 1.05 KB
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
36
37
38
39
40
41
42
43
44
45
import java.util.Scanner;
public class linearsearch {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s= new Scanner(System.in);
int i,n;
System.out.println("Enter the number of elements");
n= s.nextInt();
int a[]= new int[n];
System.out.println("Enter the number to be sorted");
for(i=0;i<n;i++)
{
a[i]= s.nextInt();
}
System.out.println("Enter the number to be searched");
int searchelement= s.nextInt();
for(i=0;i<n;i++)
{
if(a[i]==searchelement)
{
System.out.println("The location of the searched number is" +(i+1));
break;
}
}
if(i==n)
{
System.out.println("Wrong number..!!!Number is not present in the list");
}
}
}