Computer Science, asked by Vaanika, 1 year ago

does anyone knows the program of insertion and deletion of single dimensional array in java

Answers

Answered by butterflyqueen
3
import java.util.Scanner;
public class Insert_Array
{
public static void main(String[] args)
{
int n, pos, x;
Scanner s = new Scanner(System.in);
System.out.print("Enter no. of elements
you want in array:");
n = s.nextInt();
int a[] = new int[n+1];
System.out.println("Enter all the
elements:");
for(int i = 0; i < n; i++)
{
a[i] = s.nextInt();
}
System.out.print("Enter the position
where you want to insert element:");
pos = s.nextInt();
System.out.print("Enter the element you
want to insert:");
x = s.nextInt();
for(int i = (n-1); i >= (pos-1); i--)
{
a[i+1] = a[i];
}
a[pos-1] = x;
System.out.print("After inserting:");
for(int i = 0; i < n; i++)
{
System.out.print(a[i]+",");
}
System.out.print(a[n]);
}
}

butterflyqueen: mark it as brainliest please
Vaanika: marked
butterflyqueen: Thank you
Answered by chaitanyakrishn1
0
Inseetion

{Data type} []= new {data type}[no of memory spaces ]

Like int a []=new int [10]

Deletion is simple

Just cut it off by backspace

Hope it helps

Thank u ★ ★ ★
#ckc
Similar questions