-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayDeletion.java
More file actions
37 lines (27 loc) · 820 Bytes
/
ArrayDeletion.java
File metadata and controls
37 lines (27 loc) · 820 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
36
37
import java.util.Scanner;
public class ArrayDeletion {
public static void main(String args[]){
int a[]=new int[50],n,i;
Scanner in=new Scanner(System.in);
System.out.println("Enter no of elements");
n=in.nextInt();
System.out.println("Enter the elements");
for(i=0;i<n;i++)
a[i]=in.nextInt();
System.out.println("Enter an element to delete");
int x=in.nextInt();
for(i=0;i<n;i++)
{
if(a[i]==x)
{
for(int j=i;j<n-1;j++)
a[j]=a[j+1];
n--;
i--;
}
}
System.out.println("After deletion of "+x+" the elements are");
for(i=0;i<n;i++)
System.out.print(a[i]+" ");
}
}