import java.util.*;
class ArrayDelete
{
static int ar[];
public static void main(String args[])
{
System.out.println("Enter the no. of elements you want to enter");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
ar=new int[n];
System.out.println("Start to enter elements \n --------------------------------");
for(int i=0;i<n;i++)
{
System.out.println("Enter the element no " + (i+1));
ar[i]=sc.nextInt();
}
System.out.println("Enter the element/s you want to delete");
int s=sc.nextInt();
for(int i=0;i<n;)
{
if(ar[i]==s)
{
for(int j=i;j<n-1;j++)
ar[j]=ar[j+1];
n--;
}
else
i++;
}
System.out.println("Final array after operation");
for(int i=0;i<n;i++)
System.out.print(ar[i] + " ");
}
}
No comments:
Post a Comment
Convey your thoughts to authors.