0% found this document useful (0 votes)
63 views2 pages

Delete Element from Array in Java

The document provides a Java program that deletes an element from a specified position in an array. It prompts the user to input the number of elements, the elements themselves, and the position of the element to be deleted. If the position is valid, it shifts the subsequent elements to fill the gap and displays the resultant array.

Uploaded by

Anas Ali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views2 pages

Delete Element from Array in Java

The document provides a Java program that deletes an element from a specified position in an array. It prompts the user to input the number of elements, the elements themselves, and the position of the element to be deleted. If the position is valid, it shifts the subsequent elements to fill the gap and displays the resultant array.

Uploaded by

Anas Ali
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

7. Write a program to delete an element at desired position from an array.

PROGRAM:
import [Link];
class lab6ha
{
public static void main(String args[]){
Scanner sc=new Scanner([Link]);
int array[]=new int[100];
int pos,c,n;
[Link]("Enter number of elements in array");
n=[Link]();
[Link]("Enter "+n+" Element:");
for(c=0;c<n;c++)
array[c]=[Link]();
[Link]("Enter the desired position to delete the element in an array");
pos=[Link]();
if(pos>=n+1)
[Link]("Deletion not possible.");
else
{
for(c=pos-1;c<n-1;c++)
array[c]=array[c+1];
[Link]("Resultant array is");
for(c=0;c<n-1;c++)
[Link](array[c]);
}
}}

OUTPUT:

You might also like