import java.util.*;
public class Remove {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int i,count=0;
int a[]=new int[n];
for(i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
int key=sc.nextInt();
for(i=0;i<n;i++)
{
if(a[i]==key)
{
for(int j=i; j<(n-1); j++)
{
a[j] = a[j+1];
}
count++;
break;
}
}
if(count==0)
{
System.out.println("element not found");
}
else
{
System.out.print("Successfully deleted and the elements are");
for(i=0; i<(n-1); i++)
{
System.out.println(a[i]+ " ");
}
}
}
}
i/p:
6
1 2 3 4 5 6
3
o/p:
Successfully deleted and the elements are1
2
4
5
6
No comments:
Post a Comment