Page 295 - Computer science 868 Class 12
P. 295
b. All the elements starting from next to the position to be deleted till the last is shifted one column to the right.
c. Finally, the array size should be decreased by one.
Let us understand with the help of the following example.
Program 10 Write a program to delete an element in the array at a specific position.
1 import java.util.*;
2 class Delete_Array
3 {
4 int a[];
5 int n,pos;
6 Delete_Array()
7 {
8 n=0;
9 pos=0;
10 }
11
12 void input()
13 {
14 Scanner sc= new Scanner(System.in);
15 System.out.print("Enter no. of elements you want in array:");
16 n = sc.nextInt();
17 a= new int[n];
18 System.out.println("Enter all the elements:");
19 for(int i = 0; i < n; i++)
20 {
21 a[i] = sc.nextInt();
22 }
23 System.out.print("Enter the position from where you want to delete
element:");
24 pos = sc.nextInt();
25 }
26
27 void remove_element()
28 {
29 for(int i = (pos+1); i < n; i++)
293
Arrays 293

