-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraySec.java
More file actions
46 lines (42 loc) · 1.17 KB
/
Copy pathArraySec.java
File metadata and controls
46 lines (42 loc) · 1.17 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
46
import java.io.IOException;
import java.util.Scanner;
class ArraySec{
public static void main(String[] args) throws IOException{
ArrayMain arr1=new ArrayMain(100);
int elems=10;
int p;
System.out.println("Enter the elements: ");
Scanner obj=new Scanner(System.in);
try{
for(p=0;p<elems;p++)
{
int c=obj.nextInt();
arr1.setElem(p,c);
}
System.out.print("The array is : ");
for(p=0;p<elems;p++)
{
System.out.print(arr1.getElem(p)+" ");
}
System.out.println("");
System.out.printf("Enter the search element\n");
int searchElem=obj.nextInt();
for(p=0;p<elems;p++)
{
if(arr1.getElem(p)==searchElem)
break;
}
if(p==elems)
{
System.out.printf("Search element not found\n");
}
else
{
System.out.printf("Search element found at: " + p + "\n");
}
} finally
{
obj.close();
}
}
}