-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchelement20(2).java
48 lines (44 loc) · 1.16 KB
/
searchelement20(2).java
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
47
48
import java.util.Scanner;
class SearchElement
{
public static void main(String args[])
{
int size, i, del, count=0;
int arr[] = new int[50];
Scanner scan = new Scanner(System.in);
System.out.print("Enter n value : ");
size = scan.nextInt();
System.out.print("Enter 5 values : ");
for(i=0; i<size; i++)
{
arr[i] = scan.nextInt();
}
System.out.print("Enter value to be deleted : ");
del = scan.nextInt();
for(i=0; i<size; i++)
{
if(arr[i] == del)
{
for(int j=i; j<(size-1); j++)
{
arr[j] = arr[j+1];
}
count++;
break;
}
}
if(count==0)
{
System.out.print("Element Not Found..!!");
}
else
{
System.out.print("Element Deleted Successfully..!!");
System.out.print("\nNow the New Array is :\n");
for(i=0; i<(size-1); i++)
{
System.out.print(arr[i]+ " ");
}
}
}
}