package delete;
import java.util.Scanner;
import java.util.ArrayList;
public class Delete {
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
ArrayList<Integer>Array = new ArrayList<Integer>();
System.out.println("Enter Array Size: ");
int n = s.nextInt();
System.out.println("Enter Array Element: ");
for(int i =0;i<n;i++)
{
int temp = s.nextInt();
Array.add(temp);
}
System.out.println("Your Array: ");
for(int x: Array)
{
System.out.println(x);
}
System.out.println("Enter The Position You want to Delete: ");
int dlt = s.nextInt();
Array.remove(dlt); ///remove that position
System.out.println("Your Array After Delete: ");
for(int x: Array)
{
System.out.println(x);
}
}
}
Output
Enter Array Size:
4
Enter Array Element:
1 2 4 5
your array:
1
2
4
5
Enter the position you want to delete:
2
Your array after delete:
1
2
5
Add your comment